ned14 / pcpp

A C99 preprocessor written in pure Python
Other
215 stars 39 forks source link

Function macro is expanded if a preprocessor directive separates it from its arguments. #88

Open mrolle45 opened 8 months ago

mrolle45 commented 8 months ago

The C99 Standard states that a function-like macro can be separated from its argument list by whitespace. If the macro name on one line is followed by a directive and then the argument list on the next line, the macro name is considered to have no arguments and is therefore not replaced. pcpp doesn't do this. Instead, it acts as though the macro and its arguments are in adjacent lines and expands the macro.

Example:

#define X(a) (a) + 1
X
#
(3)

Should result in

X

(3)

GCC produces this result. But pcpp produces

(3) + 1

The reason is that pcpp continues to collect unexpanded tokens until it sees an #include, #define, #endif, or the end of the source file, before expanding what it has collected.