This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: second parameter of `va_start' not last named argument
- From: Ian Lance Taylor <ian at airs dot com>
- To: Antonio Coralles <noche dot suapie at reflex dot at>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 25 Mar 2005 16:56:30 -0500
- Subject: Re: second parameter of `va_start' not last named argument
- References: <4243670A.1010300@reflex.at><fc.3b9aca0095e58c9a3b9aca003906c954.426308e@reflex.at><4244897D.3020803@reflex.at>
Antonio Coralles <noche.suapie@reflex.at> writes:
> void foo(const std::string& format, ...)
> {
> unsigned num = string_count("%s", format); // counts how often "%s"
> occurs in format
> va_list p_arg;
> va_start(p_arg, num);
> for(; num > 0; --num)
> {
> const char* arg = va_arg(p_arg, const char*)
> // ... do something with the acquired string
> }
> // ...
> }
>
> as i said, the function works similar to printf, and in printf there's no
> second parameter specifying the length of the argument list...
It should be va_start (p_arg, format). va_start should always use the
last named parameter. Nothing else makes sense.
Ian