Date: Mon, 17 Nov 2014 03:08:44 +0100 From: Polytropon <freebsd@edvax.de> To: Doug Hardie <bc979@lafn.org> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: Re: vsnprintf and friends modify the va_list argument Message-ID: <20141117030844.d83bbae3.freebsd@edvax.de> In-Reply-To: <C9A11AB7-0085-464E-A6FB-F6A3603B6372@lafn.org> References: <C9A11AB7-0085-464E-A6FB-F6A3603B6372@lafn.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 16 Nov 2014 14:15:10 -0800, Doug Hardie wrote:
> I suspect this needs to be in a WARNING section of the
> printf(3) man page. The print functions that use variable
> arguments modify the argument list so that only one can
> be called.
In "man 3 printf" there is no mentioning that ap is
being modified, but "man 3 stdarg" where va_start(),
va_arg(), va_copy() and va_end() are being described,
states the following (see 3rd sentence):
The va_arg() macro expands to an expression that has the type and value
of the next argument in the call. The parameter ap is the va_list ap
initialized by va_start(). Each call to va_arg() modifies ap so that the
next call returns the next argument. The parameter type is a type name
specified so that the type of a pointer to an object that has the speci-
fied type can be obtained simply by adding a * to type.
It's important to understand that functions like vsnprintf(),
vprintf() and fprintf() rely on the va_* functions / macros
which _modify_ the va_list pointer.
An additional hint is provided by the vprintf() prototypes
where no "const" is mentioned in regards of the ap parameter:
int vprintf(const char * restrict format, va_list ap);
Maybe adding stdarg(3) to printf(3)'s SEE ALSO section would
be a helpful choice here.
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141117030844.d83bbae3.freebsd>
