Perhaps you just need to add a few extra macros. The key is that when using the ## operator to work with the token, the preprocessor will not expand its operands. But if you add another layer of macros, the preprocessor will expand these arguments. For instance:
#define CASE1 text1 #define CASE2 text2 #define CASE3 text3 #define SCENARIO 3 #define TOKENPASTE_HELPER(x, y) x ## y #define TOKENPASTE(x, y) TOKENPASTE_HELPER(x, y) #define FUNCTION TOKENPASTE(CASE, SCENARIO)
When the preprocessor extends FUNCTION , it extends TOKENPASTE . When it expands with TOKENPASTE , it expands its formulas (therefore, SCENARIO is replaced with 3 ), since none of its arguments is an operand of the marker operator. Then it extends TOKENPASTE_HELPER , which makes the actual insertion of the marker to make CASE3 . Finally, he extends the CASE3 macro to get text3 .
source share