I want to create a define using macro expansion. The crated define shall hold the value of an other define. :)
Example:
#define ONE 1
#define TWO 2
#define MACRO(x, y) ...
...
#define MACRO_1_2 3
My question is: how can I resolve / use the value of a define in macro expansion?
I have tried to use
#define TEST_MACRO_V2(x, y) TEST_MACRO_V2_"x"_"y"
, but I get the following error:
main.c:18:34: error: ‘TEST_MACRO_V2_’ undeclared (first use in this function) #define TEST_MACRO_V2(x, y) TEST_MACRO_V2_"x"_"y"
My test code:
#include <stdio.h>
#define ONE 1
#define TWO 2
#define TEST_MACRO_V1(x, y) TEST_MACRO_V1_##x##_##y
#define TEST_MACRO_V1_ONE_TWO 3
//#define TEST_MACRO_V2(x, y) TEST_MACRO_V2_##('x')##_##('y') -> this version does not work
#define TEST_MACRO_V2(x, y) TEST_MACRO_V2_"x"_"y"
#define TEST_MACRO_V2_1_2 4
int main()
{
printf("Test Macro V1: %d\n", TEST_MACRO_V1(ONE, TWO));
printf("Test Macro V2: %d\n", TEST_MACRO_V2(ONE, TWO));
return 0;
}
Note: TEST_MACRO_V1 works fine. I need TEST_MACRO_V2.
TEST_MACRO_V2(ONE, TWO)should be, or what the expected output is of the program you postedMACRO_1_2,TEST_MACRO_V1_ONE_TWOandTEST_MACRO_V2_1_2?