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