#38·chibicc

Token concatenation not done in object-like macros

Author: kukrimateCreated Feb 16, 2021Updated Feb 17, 2025

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