title: Variadic UNUSED function/macro
body: <p>A well-known and portable way to suppress C compiler warnings about unused variables is (see <a href="https://stackoverflow.com/questions/3599160/unused-parameter-warnings-in-c-code">unused parameter warnings in C code</a>):</p>
  
  <pre><code>#define UNUSED(x) (void)(x)
  </code></pre>
  
  <p>I'm looking for a way to generalize this to take multiple inputs (of different type):</p>
  
  <pre><code>void foo(int a, long b, void* c){
  
     /* Want this: */
     ALL_UNUSED(a, b, c);
  
     /* instead of: */
     UNUSED(a);
     UNUSED(b);
     UNUSED(c);
  }
  </code></pre>
  
  <p>One way that seems to do the trick is to use a variadic function</p>
  
  <pre><code>static inline void ALL_UNUSED(int dummy, ...) {}
  </code></pre>
  
  <p>However, I suspect this solution is objectionable in the expert eye. </p>
  
  <p>Is there a standard-compliant and portable (i.e. not using <code>__attribute__((unused))</code>) way to make a variadic UNUSED() function/macro? Many thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>There does not seem to exist a clean way of doing what I asked for in the context of C99 or the C preprocessor. Such is life.</p>
  
  <p>In his answer below, @Dabo shows a pretty interesting way of doing what I asked for using a series of macros. This is neat and informative (at least to me), so I accept that answer. That said, I would not deploy it in a big project because it's tearse enough to outweigh the benefit it brings (in my eyes). But people will come to different conclusions here. </p>
  
  <p>As noted below, the approach of using an empty variadic function is not perfect either. While it's a pretty elegant one-liner, it will provoke warnings about unititialized variables (if they are). Also, you have to trust your compiler to completely optimize it away, which I object to in principle but that all compilers I have tried with actually do.</p>
  
  <p>One relevant case is when stubbing functions after an early high-level interface design phase. Then your unused variables will all be function arguments and initialized by definition, and the following approach works fine</p>
  
  <pre><code>static inline void UNUSED(int dummy, ...) {}
  
  void foo(int a, long b, void* c){
      UNUSED(a, b, b); /* No warnings */
  }
  </code></pre>