[cfe-dev] #define behavior
Neil Booth
neil at daikokuya.co.uk
Wed Dec 5 03:24:13 PST 2007
Bill Wendling wrote:-
> Here's an interesting question that occurred in one of the OCCC
> entries that I was compiling with clang. This program:
I would hope OCCC entries would be valid C.
> $ cat d.c
> #define x =
>
> int foo(int *k) {
> return *k *x 37;
> }
>
> Generates this:
>
> $ clang -ast-print d.c -triple=i686-apple-darwin9
> typedef char *__builtin_va_list;
> d.c:4:14: error: expected expression
> return *k *x 37;
> ^
>
> int foo(int *k) {
> }
>
> 1 diagnostic generated.
>
> GCC also balks at this. It appears that there's a space being
> inserted after the "*" and before the "=" that "x" becomes. Is this
> expected?
Standard C works on tokens, not text, so the code is invalid as
* and = are two separate tokens.
Neil.
More information about the cfe-dev
mailing list