Re: c language functions

From: Rodrigo Barboza <rodrigombufrj(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: c language functions
Date: 2013-04-03 19:25:42
Message-ID: CANs8QJb_dRmwmWFSmKwx=+J8iqs4rRHM5_S18AvpitaR20PzSQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Well, I was checking inside my function the type of the second argument and
switching between the allowed types.
This way kind of does the same thing of many functions, doesn't it?

On Wed, Apr 3, 2013 at 3:39 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Rodrigo Barboza <rodrigombufrj(at)gmail(dot)com> writes:
> > Why not useful?
> > If I don't make it receive anyelement, I will have to create an add
> > function for each type.
>
> If you make it anyelement, then you're contracting to be able to add
> any datatype whatsoever to a my_uint. This is nonsensical.
>
> You'd be better off declaring several specific addition functions,
> one for each other type. This will be an order of magnitude easier
> to write, and probably run an order of magnitude faster too, because
> just checking to see what type you got would already be significantly
> more expensive than adding a couple of integers ought to be.
>
> Look at the built-in types and functions for precedent. There are
> indeed separate functions for int2 + int2, int2 + int4, int4 + int2,
> int4 + int4, etc etc. If we were starting from scratch, we might reduce
> that to just int4 + int4 and rely on the implicit coercion from int2 to
> int4 to handle the other cases; but there's no way we'd put in run-time
> type determination.
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2013-04-03 19:33:05 Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Previous Message Jeff Davis 2013-04-03 19:15:53 Re: regression test failed when enabling checksum