title: Adding extra arguments to a C-style variadic argument list
body: <p>I'm trying to write a wrapper for a C-style variadic function like printf, which adds some extra arguments, but I'm having trouble with it:</p>
  
  <pre><code>void printf(char* fmt, ...);  // the thing I'm trying to wrap
  
  void wrapper(char* fmt, ...)
  {
      printf(fmt, extra_arg1, extra_arg2, /* the variadic arguments */);
  }
  </code></pre>
  
  <p>but what do I write for <code>/* the variadic arguments */</code>?</p>
  
  <p>Even if the function I'm trying to wrap has a version that takes a <code>va_list</code>, I can't do it:</p>
  
  <pre><code>void vprintf(char* fmt, va_list args);
  
  void wrapper(char* fmt, ...)
  {
      va_list args;
      va_start(args, fmt);
      vprintf(fmt, extra_arg1, extra_arg2, args);
      va_end(args);
  }
  </code></pre>
  
  <p><code>extra_arg1</code>, <code>extra_arg2</code> and <code>args</code> don't magically turn into a <code>va_list</code> that <code>vprintf</code> expects.</p>
  
  <p>I know I could write a macro and use <code>__VA_ARGS__</code>:</p>
  
  <pre><code>void printf(char* fmt, ...);  // the thing I'm trying to wrap
  
  #define wrapper(fmt, ...) printf(fmt, extra_arg1, extra_arg2, __VA_ARGS__)
  </code></pre>
  
  <p>but I'm trying to avoid that and write the wrapper as a function. Is there a way to do that?</p>
  
  <p>(By the way, I can't use C++11 variadic templates either.)</p>