ned14 / pcpp

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

Nested concat not working correctly (different to every other compiler) #13

Closed skirsten closed 6 years ago

skirsten commented 6 years ago
#define CONCAT(a, b) a ## _ ## b
#define CONCAT_MULTIPLE(prefix) CONCAT(prefix, BANANA) | CONCAT(prefix, APPLE) | CONCAT(prefix, GRAPE)

#define CONCAT_NESTED(val) CONCAT(NESTED, val)
#define CONCAT_MULTIPLE_NESTED(prefix) CONCAT_NESTED(CONCAT(prefix, BANANA)) | CONCAT_NESTED(CONCAT(prefix, APPLE)) | CONCAT_NESTED(CONCAT(prefix, GRAPE))

CONCAT_MULTIPLE(FOOD);
CONCAT_MULTIPLE_NESTED(FOOD);

pcpp:

FOOD_BANANA_APPLE_GRAPE | FOOD_BANANA_APPLE_GRAPE | FOOD_BANANA_APPLE_GRAPE;
NESTED_FOOD_BANANA | NESTED_FOOD_BANANA_APPLE | NESTED_FOOD_BANANA_APPLE_GRAPE;

gcc, g++, clang, clang++, cl (MSVC):

FOOD_BANANA | FOOD_APPLE | FOOD_GRAPE;
NESTED_FOOD_BANANA | NESTED_FOOD_APPLE | NESTED_FOOD_GRAPE;

Its obvious whos in the wrong. I couldn't find the problem but i dont think its with the concatting and more with the macro expansion.

ned14 commented 6 years ago

Fixed!

skirsten commented 6 years ago

Thanks! Your project was very helpful to me. Keep it up.