public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* second parameter of `va_start' not last named  argument
@ 2005-03-25 10:32 Antonio Coralles
  2005-03-25 19:38 ` Ian Lance Taylor
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Antonio Coralles @ 2005-03-25 10:32 UTC (permalink / raw)
  To: gcc-help

is there a way to prevent this gcc warning?
in a code similar to

void foo(const std::string& format, ...);

i determine the neccessary number of arguments by counting the 
occurences of "%s" in format,
similar to printf. therefore, there is no need for the caller to pass 
the number of arguments as a second
argument.

thanks
             Antonio

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: second parameter of `va_start' not last named  argument
  2005-03-25 10:32 second parameter of `va_start' not last named argument Antonio Coralles
@ 2005-03-25 19:38 ` Ian Lance Taylor
  2005-03-25 19:48 ` corey taylor
       [not found] ` <fc.3b9aca0095e58c9a3b9aca003906c954.426308e@reflex.at>
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 2005-03-25 19:38 UTC (permalink / raw)
  To: Antonio Coralles; +Cc: gcc-help

Antonio Coralles <noche.suapie@reflex.at> writes:

> is there a way to prevent this gcc warning?
> in a code similar to
> 
> void foo(const std::string& format, ...);
> 
> i determine the neccessary number of arguments by counting the
> occurences of "%s" in format,
> similar to printf. therefore, there is no need for the caller to pass
> the number of arguments as a second
> argument.

If you want help, you will need to post a complete test case.
Specifically, how are you calling va_start?  When you call va_start,
you must pass it the last named argument in the function.  Any other
usage is invalid.

Ian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: second parameter of `va_start' not last named argument
  2005-03-25 10:32 second parameter of `va_start' not last named argument Antonio Coralles
  2005-03-25 19:38 ` Ian Lance Taylor
@ 2005-03-25 19:48 ` corey taylor
       [not found] ` <fc.3b9aca0095e58c9a3b9aca003906c954.426308e@reflex.at>
  2 siblings, 0 replies; 5+ messages in thread
From: corey taylor @ 2005-03-25 19:48 UTC (permalink / raw)
  To: Antonio Coralles; +Cc: gcc-help

Exactly, you know the number and so you provide the value to va_start.
 The user calling foo does not provide this.

corey


On Fri, 25 Mar 2005 02:19:06 +0100, Antonio Coralles
<noche.suapie@reflex.at> wrote:
> is there a way to prevent this gcc warning?
> in a code similar to
> 
> void foo(const std::string& format, ...);
> 
> i determine the neccessary number of arguments by counting the
> occurences of "%s" in format,
> similar to printf. therefore, there is no need for the caller to pass
> the number of arguments as a second
> argument.
> 
> thanks
>              Antonio
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: second parameter of `va_start' not last named  argument
       [not found] ` <fc.3b9aca0095e58c9a3b9aca003906c954.426308e@reflex.at>
@ 2005-03-25 21:56   ` Antonio Coralles
  2005-03-26  0:43     ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Antonio Coralles @ 2005-03-25 21:56 UTC (permalink / raw)
  To: gcc-help

Ian Lance Taylor wrote:

> Antonio Coralles <noche.suapie@reflex.at <mailto:>> writes:
>
>> is there a way to prevent this gcc warning?
>> in a code similar to
>>
>> void foo(const std::string& format, ...);
>>
>> i determine the neccessary number of arguments by counting the
>> occurences of "%s" in format,
>> similar to printf. therefore, there is no need for the caller to pass
>> the number of arguments as a second
>> argument.
>
> If you want help, you will need to post a complete test case.
> Specifically, how are you calling va_start?  When you call va_start,
> you must pass it the last named argument in the function.  Any other
> usage is invalid.
>
> Ian

Here is a test case:

the source looks like this:

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...

antonio

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: second parameter of `va_start' not last named  argument
  2005-03-25 21:56   ` Antonio Coralles
@ 2005-03-26  0:43     ` Ian Lance Taylor
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 2005-03-26  0:43 UTC (permalink / raw)
  To: Antonio Coralles; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-03-25 21:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-25 10:32 second parameter of `va_start' not last named argument Antonio Coralles
2005-03-25 19:38 ` Ian Lance Taylor
2005-03-25 19:48 ` corey taylor
     [not found] ` <fc.3b9aca0095e58c9a3b9aca003906c954.426308e@reflex.at>
2005-03-25 21:56   ` Antonio Coralles
2005-03-26  0:43     ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).