I was looking at the program at http://www0.us.ioccc.org/1988/westley.c, mentioned in another SO answer – it’s supposed to print the value of pi, about 3.142, but when I compile it and run it I get 0.250. It looks like when the GCC preprocessor (both 4.1.2 and 3.4.6 tested) runs on the code, it converts
#define _ -F<00||--F-OO--;
_-_-_
to
-F<00||--F-OO--;- -F<00||--F-OO--;- -F<00||--F-OO--;
but I think, for the program to work, it should be
-F<00||--F-OO--;--F<00||--F-OO--;--F<00||--F-OO--;
i.e. GCC is inserting an extra space before the “macro” expansion. Is that the way #define is supposed to work? (Has that changed since 1988?)
EDIT: Also, any information about how to prevent those spaces from showing up would be appreciated.
The preprocessor operates on tokens, not strictly text. So technically it doesn’t “put a space” in between, but unless you explicitly tell it to paste two tokens together with the
##operator, it won’t do it. In this case the two-‘s across macro lines are counted as two different tokens – both meaning unary minus, not decrement.see also: http://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation