I have a macro where I pass in an argument and use that define a new variable based on the name of the input:
#define DO_X(x) char _do_x_var_ ## x; /* other things */
The problem is if I pass in a struct variable, it breaks:
DO_X(some_struct->thing)
becomes:
char _do_x_var_some_struct->thing; /* other things */
EDIT: What I want it to evaluate to is:
char _do_x_var_some_struct__thing; /* other things */
(or any valid variable name containing something similar to the input)
What I actually want is for these to work:
#define DO_X(x) for(char _do_x_var_ ## x; /*things*/)
DO_X(x){
DO_X(y) {
/*things*/
}
}
DO_X(object->x){
DO_X(object->y) {
/*things*/
}
}
but for these to fail:
#define DO_X(x) for(char _do_x_var_ ## x; /*things*/)
DO_X(x){
DO_X(x) { // <-- multiple definition of _do_x_var_x
/*things*/
}
}
DO_X(object->x){
DO_X(object->x) { // <-- multiple definition of _do_x_var_object__x (or whatever)
/*things*/
}
}
Is there some way to make this work? Maybe replacing ->
with __
or something? I've found ways to concatenate, but not replace strings..