second parameter of `va_start' not last named argument
Ian Lance Taylor
ian@airs.com
Sat Mar 26 00:43:00 GMT 2005
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
More information about the Gcc-help
mailing list