Whitespace matters – until it doesn’t
The following piece of code is not an extraordinarily complicated snippet:
#include <cstdio> #define STR_I(x) #x #define STR(x) STR_I(x) #define JOIN(x,y) (x y) #define Hello(x) HELLO int main(void){ printf("%s\n", STR(JOIN(Hello, World))); printf("%s\n", STR(JOIN(Hello,World ))); }
The not-so-complex code defines a series of macros to manipulate strings and concatenate tokens. STR_I(x)
stringifies its argument, STR(x)
ensures full macro expansion before stringification, JOIN(x,y)
concatenates two arguments with a space, and Hello(x)
is defined but, strangely, unused.
What comes up are two most important printf
calls in the lifetime of this short program. In the first printf
call, JOIN(Hello, World)
expands to (Hello World)
, which is then stringified to "(Hello World)"
. That’s nothing overly complicated.
However, the fun part comes...