Re: c language functions
От | Rodrigo Barboza |
---|---|
Тема | Re: c language functions |
Дата | |
Msg-id | CANs8QJb_dRmwmWFSmKwx=+J8iqs4rRHM5_S18AvpitaR20PzSQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: c language functions (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: c language functions
|
Список | pgsql-hackers |
<div dir="ltr">Well, I was checking inside my function the type of the second argument and switching between the allowedtypes.<div style="style">This way kind of does the same thing of many functions, doesn't it?</div></div><div class="gmail_extra"><br/><br /><div class="gmail_quote">On Wed, Apr 3, 2013 at 3:39 PM, Tom Lane <span dir="ltr"><<a href="mailto:tgl@sss.pgh.pa.us"target="_blank">tgl@sss.pgh.pa.us</a>></span> wrote:<br /><blockquote class="gmail_quote"style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Rodrigo Barboza<<a href="mailto:rodrigombufrj@gmail.com">rodrigombufrj@gmail.com</a>> writes:<br /> > Why not useful?<br/> > If I don't make it receive anyelement, I will have to create an add<br /> > function for each type.<br/><br /></div>If you make it anyelement, then you're contracting to be able to add<br /> any datatype whatsoeverto a my_uint. This is nonsensical.<br /><br /> You'd be better off declaring several specific addition functions,<br/> one for each other type. This will be an order of magnitude easier<br /> to write, and probably run an orderof magnitude faster too, because<br /> just checking to see what type you got would already be significantly<br /> moreexpensive than adding a couple of integers ought to be.<br /><br /> Look at the built-in types and functions for precedent. There are<br /> indeed separate functions for int2 + int2, int2 + int4, int4 + int2,<br /> int4 + int4, etc etc. If we were starting from scratch, we might reduce<br /> that to just int4 + int4 and rely on the implicit coercion fromint2 to<br /> int4 to handle the other cases; but there's no way we'd put in run-time<br /> type determination.<br /><br/> regards, tom lane<br /></blockquote></div><br /></div>
В списке pgsql-hackers по дате отправления: