I was trying some awkward preprocessing and came up with something like this:
#include <stdio.h>
#define SIX =6
int main(void)
{
int x=6;
int y=2;
if(x=SIX)
printf("X == 6\n");
if(y=SIX)
printf("Y==6\n");
return 0;
}
gcc gives me the errors:
test.c: In function ‘main’:
test.c:10:8: error: expected expression before ‘=’ token
test.c:12:8: error: expected expression before ‘=’ token
Why is that?
if(x= =6). I'm not sure why the space is inserted... presumably someone who knows one of the C specifications much better than me will come along...if(x=SIX), it hasif,(,x,=, andSIX. When it macro expandsSIX, it has extra tokens=and6. But two adjacent tokens=are not the same as one token==(and are in fact invalid C syntax) — hence the compilation error.