On 2010-Jul-26 02:52:50 -0700, Simon King <simon.k...@nuigalway.ie> wrote: >Hi! > >On 26 Jul., 11:09, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote: >> More concretely: in the pari source file src/headers/parigen.h, there is >> #define lgefint(x) ((long)(((ulong*)(x))[1] & LGBITS)) >> >> But in Sage, in sage/libs/pari/decl.pxi, there is >> long lgefint(GEN x) > >To my understanding, it is the correct way. > >"#define ..." means that lgefint(...) is replaced by ((long)(((ulong*) >(...))[1] & LGBITS)) in all C-files including that header. This also >holds for the C-files generated by Cython.
Yes. Note that this can lead to traps - in particular, placing a function declaration after a macro that is intended to override that function can lead to unexpected syntax errors: #define lgefint(x) ((long)(((ulong*)(x))[1] & LGBITS)) long lgefint(GEN x); Turns into long ((long)(((ulong*)(GEN x))[1] & LGBITS)); which is not legal C. >Probably one "clean" way of usage would be to define a proper function >that wraps the macro. In the above example, the macro is being used as a pseudo function and replacing it with an inline function would probably be beneficial. -- Peter Jeremy
pgpCdaIZG0x7v.pgp
Description: PGP signature