I have the following code:
#define MY_MACRO(PARAM) int PARAM_int; double PARAM_double; [subsequent instructions]
Unfortunately, it does not work, meaning that PARAM is not replaced inside the variables names. Is this solvable some way?
I have the following code:
#define MY_MACRO(PARAM) int PARAM_int; double PARAM_double; [subsequent instructions]
Unfortunately, it does not work, meaning that PARAM is not replaced inside the variables names. Is this solvable some way?
PARAM_int
is considered to be a single token, that is distinct from PARAM
. You can concatenate tokens in a macro definition with ##
:
#define MY_MACRO(PARAM) int PARAM ## _int; double PARAM ## _double;
Now, PARAM
will expand to whatever you invoke the macro with, and then the resulting token will be pasted together with _int
and _double
.