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: Antonio Coralles <noche dot suapie at reflex dot at>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 25 Mar 2005 22:58:21 +0100
- Subject: Re: second parameter of `va_start' not last named argument
- References: <4243670A.1010300@reflex.at> <fc.3b9aca0095e58c9a3b9aca003906c954.426308e@reflex.at>
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