GCC likes to break your code
I was trying to write a macro that, based on the endianness of the target machine, would either index an array, or directly access a struct field…
#if __BYTE_ORDER == __BIG_ENDIAN
#define GET(x, fieldname) ((struct x*)x)->##fieldname
#else
#define GET(x, fieldnum) setfield(x, fields[fieldnum]);
#endif
This used to work, but apparently GCC 3.x breaks this - I got errors like ‘pasting “->” and “field” does not give a valid preprocessing token.’ There were a lot of results on google when searching for “does not give a valid preprocessing token”… I eventually downloaded somebody’s gzipped patch, which inside just replaced ## with /**/ … simple, eh? So I thought I’d put this up so its out there with a simple, non-gzipped explanation of how to get around the issue of ## not working for pasting anymore.
