#define var(N) variable ## N
var(1) got variable1
I want to get variable, how can I define the macro?
var( ) works, but it always give a warning. is there any other solutions?
#define var(N) variable ## N
var(1) got variable1
I want to get variable, how can I define the macro?
var( ) works, but it always give a warning. is there any other solutions?
In fact the version that you presented always needs a non-empty argument for N
. If you have a modern C compiler you can use this construct:
#define var(...) variable ## __VA_ARGS__
This accepts empty arguments and you should be fine.
"modern" here means C as of 1999.
Don't use the argument inside the macro:
#define var(n) variable