I have a lot of lines of code like below:
sp_setup_point( setup, get_vert(vertex_buffer, i-0, stride) );
for each of them, I want to be able to extract (i-0) and pass it to another function. like:
sp_setup_point( setup, get_vert(vertex_buffer, i-0, stride) );
my_test_func(i-0);
so I wrote two macro:
#define GET_VERT(_x, _y, _z) get_vert(_x, _y, _z) , _y
#define SP_SETUP_POINT(_x, _y, _z) sp_setup_point(_x, _y); my_test_func(_z);
and call them like:
SP_SETUP_POINT( setup, GET_VERT(vertex_buffer, i-0, stride));
however, it does not give what I want, it expands to:
sp_setup_point(setup, get_vert(vertex_buffer, i-0, stride), i-0); my_test_func();
and MSVC compiler complains
not enough actual parameters for macro 'SP_SETUP_POINT'
I searched quite a bit, according to https://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html
Macro arguments are completely macro-expanded before they are substituted into a macro body, unless they are stringified or pasted with other tokens. After substitution, the entire macro body, including the substituted arguments, is scanned again for macros to be expanded. The result is that the arguments are scanned twice to expand macro calls in them
the argument are fully expanded, but the additional argument is not recognized. how it that ? any suggestion is appreciated.