title: Is it safe to pass a va_list to another function without using va_copy?
body: <p><a href="http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html">This blog post</a> claims that passing a <code>va_list</code> to another function like in the following code is unsafe, and that the <code>va_list</code> must first be copied using <code>va_copy</code>:</p>
  
  <pre><code>void
  foo_ap(const char *fmt, va_list ap)
  {
      char buf[128];
  
      vsnprintf(buf, sizeof(buf), fmt, ap);
  
      // now, do something with buf ...
  }
  </code></pre>
  
  <p>Like one of the comments to the blog post mentions, I can't see how this would be unsafe, as the C99 spec states (7.15):</p>
  
  <blockquote>
    <p>The object <code>ap</code> may be passed as an argument to another function; if that function invokes the <code>va_arg</code> macro with parameter <code>ap</code>, the value of <code>ap</code> in the calling function is indeterminate and shall be passed to the <code>va_end</code> macro prior to any further reference to <code>ap</code>.</p>
  </blockquote>
  
  <p>(As long as <code>foo_ap</code> doesn't reference <code>ap</code> after passing it on, the second part of the sentence doesn't seem to apply anyway.) The author of the blog post says in another comment that he might be wrong, but maybe someone can add some clarification. Do I really have to use <code>va_copy</code> to be on the safe side? Or are there any platforms that don't conform to the spec and require the use of <code>va_copy</code>?</p>