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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Antonio Coralles <noche.suapie@xxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux