macros and functions

Kevin Ryde user42@zip.com.au
Tue, 04 Mar 2003 08:18:22 +1000


Jason Moxham <J.L.Moxham@maths.soton.ac.uk> writes:
>
> What existing function (mpn if possible) has this property , a nice
> simple one please.

In glibc stdio.h you can see putc given first as a prototype then a
#define.  When used as a function pointer it hits the prototype.

I don't know if it's a normal feature for cpp to ignore the define
when it's used without a parameter list.  It could well be normal, but
glibc is highly dependent on gcc so it may not have been exercised
widely.

We can't do this in gmp however, because it would mean the function
would be plain mpz_foo, whereas we want it to come out as __gmpz_foo.
I think I tried an extra level of macroing one time, without success.

nisse@lysator.liu.se (Niels M=F6ller) writes:
>
> If you want the same name for the function and the "macro", that may
> be easier to do using inline than with the preprocessor.

That probably comes out cleanest.  The only thing to consider is that
not all compilers have an inline, and not all are recognised by the
inline business in gmp.h, so one could end up with applications
written in a style that only certain compilers can do a good job with.
Better to try to ensure everyone is equal.