GCC CPP not expanding macro correctly?

Neil Booth neil@daikokuya.co.uk
Wed Apr 23 07:26:00 GMT 2003


AWLaFramboise@aol.com wrote:-

> Hi,
> 
> I have found what appears to be very odd behavior, possibly a bug, according to my reading of the C standard.  Test case:
> -----
> #define FIRST() FUNC
> #define SECOND() ()
> #define FUNC() 0
> int main() {
>   return FIRST()SECOND();
> }
> -----
> After preprocessing (translation stage 4), this code looks like (according to gcc 3.2.2 with gcc -E):
> int main() {
>   return FUNC();
> }
> 
> Question is: Why does this code not expand to this?
> int main() {
>   return 0;
> }

Because the preprocessor only checks for '(' once, and it doesn't see
'(' it sees SECOND.

Neil.



More information about the Gcc mailing list