Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need some indirection. With C99:</p> <pre><code>#define NEED3ARGS(a1,a2,a3) ( "[" #a1 " + " #a2 " + " #a3 "]" ) #define INVOKE_NEED3ARGS(...) NEED3ARGS(__VA_ARGS__) #define MULTIARG() ARG1, ARG2, ARG3 INVOKE_NEED3ARGS( MULTIARG() ) </code></pre> <p>(C99 isn't strictly required; you can replace the variadic macro with a fixed-arity macro.)</p> <p>If you need to compile your source using Visual C++, you'll need even more indirection (because of <a href="http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement">a compiler bug</a>):</p> <pre><code>#define NEED3ARGS(a1,a2,a3) ( "[" #a1 " + " #a2 " + " #a3 "]" ) #define INVOKE_NEED3ARGS_(...) NEED3ARGS __VA_ARGS__ #define INVOKE_NEED3ARGS(...) INVOKE_NEED3ARGS_((__VA_ARGS__)) #define MULTIARG() ARG1, ARG2, ARG3 INVOKE_NEED3ARGS( MULTIARG() ) </code></pre> <hr> <p>As for <em>why</em> indirection is needed: a macro argument is not evaluated and macro-replaced until it is substituted into the replacement list. So, when you try <code>NEED3ARGS(MULTIARG())</code>, <code>MULTIARG()</code> will not be evaluated until <em>after</em> macro invocation has begun, so it's treated as a single argument.</p> <p>The <code>INVOKE_NEED3ARGS</code> macro ensures that its arguments are completely evaluated before <code>NEED3ARGS</code> is invoked. The <code>__VA_ARGS__</code> is substituted by the macro-replaced arguments to <code>INVOKE_NEED3ARGS</code>, which is <code>ARG1, ARG2, ARG3</code>, then <code>NEED3ARGS</code> is invoked with those arguments.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload