How to use #if inside #define in the C preprocessor?
You can simulate conditionals using macro token concatenation as follows: #define DEF_CONST(b_const) DEF_CONST_##b_const #define DEF_CONST_true const #define DEF_CONST_false Then, /* OK */ DEF_CONST(true) int x; /* expands to const int x */ DEF_CONST(false) int y; /* expands to int y */ /* NOT OK */ bool bSomeBool = true; // technically not C 🙂 DEF_CONST(bSomeBool) … Read more