I would like to define a macro with a variable number of parameters which prints the name and value of each given parameter.
For instance :
MACRO(x)
would print x = 123
MACRO(x,y)
would print x,y = 123,666
A better macro would be more readable
BETTER_MACRO(x,y)
would print x = 123, y = 666
For one variable, I can manage with :
#define MACRO(...) cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << endl;
For more, it does not work.
By acting this way, some auxiliary questions come to my mind.
1) How to get the number of variables given to the macro? 2) How to access each argument?
Guess naïvely, we can answer these two questions.
We then hope to define the macro in the following way.
#define BETTER_MACRO(...) {for (int i=0;i<=nb_variables;i++) {cout << #var[i] << var[i];}}