🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #19

Re: stdarg facility, va_start more than once?

#19
From: John F. Woods
Date: Wed, 28 Oct 1992 17:09
28 lines
1806 bytes
mgk@sql.sybase.com (Michael Keirnan aka Joe Cool) writes:
>Is using the macro va_start more than once in a function legal in
>ANSI C? I was thinking of something along the lines of:
>#include <stdarg.h>
>void two_pass_arg_eater(int first_arg, ...)
>  {
>    va_list ap;
>    va_start(ap, first_arg);
>    /* while ... va_arg(ap, type) ... process args pass 1 */
>    va_end(ap);
>    va_start(ap, first_arg);
>    /* while ... va_arg(ap, type) ... process args pass 2 */
>    va_end(ap);
>  }
>My trusty Harbison and Steele (3rd ed.) does not forbid it as far as I
>can tell, but I'm looking for a more authoritative answer.

Looking in the standard, I don't see an explicit statement that va_start()
may be used more than once, but there certainly is none saying it may not,
and va_end() is described (partially) like this:  "The va_end macro may
modify ap so that it is no longer usable (without an intervening invocation
of va_start)."  Additionally, it is mentioned that if you pass ap to another
function, "the value of ap in the calling function is indeterminate and
shall be passed to the va_end macro prior to any further reference to ap."
Of course, there may be no further reference to ap after calling va_end
unless you call va_start afterwards.  Sounds like clear documentation of
the Committee's intent, and strong circumstantial evidence that it may be
invoked more than once.
Technical Details
Message-ID: <17660@ksr.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!world!ksr!jfw
References: <MGK.92Oct27155222@cedar.sql.sybase.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!world!ksr!jfw
From: jfw@ksr.com (John F. Woods)
Newsgroups: comp.std.c
Subject: Re: stdarg facility, va_start more than once?
Message-ID: <17660@ksr.com>
Date: 28 Oct 92 12:09:34 EST
References: <MGK.92Oct27155222@cedar.sql.sybase.com>
Sender: news@ksr.com
Distribution: comp
Lines: 28