This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: second parameter of `va_start' not last named argument


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]