How to fix the macro expansion issue below ?
#define GET_VAL 3,2
#define ADD_VAL(val0, val1) ((val0) + (val1))
void foo()
{
int res = ADD_VAL(GET_VAL);
}
The macro is getting expanded as below and resulting in an error. I am using MSVC 2019
res = 3,2 + ;
I even tried using a helper macro as below, but still getting the same error.
#define GET_VAL 3,2
#define ADD_VAL1(val0, val1) (val0 + val1)
#define ADD_VAL(val) ADD_VAL1(val)
Expecting expansion: ADD_VAL(GET_VAL); --> ADD_VAL(3, 2); --> 3 + 2
ptr
appearing in the expansion. Your second example should produce the expansion you expect, what error did you get?I even tried using a helper macro as below, but still getting the same error.
What error?Expecting expansion: ADD_VAL(GET_VAL); --> ADD_VAL(3, 2); --> 3 + 2
And I am also expecting this expansion with another pass, this is what should happen.