chibicc
chibicc copied to clipboard
Token concatenation not done in object-like macros
Hello,
chibicc does not evaluate the ## operator in the replacement list of an object-like macros.
The C standard says, to quote ISO/IEC 9899:1999:
For both object-like and function-like macro invocations, before the replacement list is reexamined for more macro names to replace, each instance of a ## preprocessing token in the replacement list (not from an argument) is deleted and the preceding preprocessing token is concatenated with the following preprocessing token.
For example the following:
#define obj a ## b
obj
expands to:
a ## b
even though the expected expansion by the standard (which gcc and clang conforms to) is:
ab
EDIT: typo
Confirmed. I have no idea how this behavior can be useful, but this is indeed a bug in chibicc.
I agree, it's not useful behaviour. I came across it when comparing the output of chibicc to my own implementation of macro expansion and noticed the difference.