Nice, I didn't know you could do implicit string concatenation.
counting_pine wrote:Note: A space (or ampersand) is necessary after #X otherwise the following quote gets sucked into the string literal of #X, as seen here:
#define p(x) print "abc"#x"ghi"
p(def) ''expanded to: print "abc"$"def""ghi"
That probably shouldn't happen..?
Remember that the preprocessor is just a source code manipulation engine, it does not understand the code it generates. The compiler (which does understand it) passes over the code only after the preprocessor mangles it up. So while the preprocessor is parsing its own input correctly, the output it generates is somewhat unexpected in this case thanks to the way quotations work inside strings.
The only reason the same thing doesn't happen to the left side is because stringize adds the $, which I suppose it adds to explicitly prevent escape sequence expansion, even though it doesn't really need to.
gothon wrote:Remember that the preprocessor is just a source code manipulation engine, it does not understand the code it generates. The compiler (which does understand it) passes over the code only after the preprocessor mangles it up. So while the preprocessor is parsing its own input correctly, the output it generates is somewhat unexpected in this case thanks to the way quotations work inside strings.
But ideally if the macro sees two separate tokens, then so should the preprocessed text (unless ## is used).
I guess it may be easy enough to fix by making the preprocessor append a space to stringized literals..