Category : c-preprocessor

Consider the following simple C/C++ example: #define FOO … #ifdef FOO bar++; #endif OK, now I would like to fit that (any any other similar) conditional into one line for the code readability sake (the code has tens of single-line statements that all need to be conditional each depending on different define). Something that, when ..

Read more

You can define a variadic macro in C++ like: #define FOO(x, …) bar(x, __VA_ARGS__) But calling FOO as FOO(1) results in the macro expansion bar(1,) which is obviously a syntactical error and won’t compile. Therefore GCC includes a GNU extension: #define FOO(x, …) bar(x, ##__VA_ARGS__) which would expand the given example to the desired result ..

Read more

I’m trying to implement C/C++-compatible macro processing. I can correctly handle many corner cases, including those discussed here: Understanding the behavior of C's preprocessor when a macro indirectly expands itself. However, there’s a corner case where I get a different answer from gcc and clang, so am obviously wrong. The code is similar to the ..

Read more