This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
va_list question
- From: "Bob Boz" <gcc_compiler at yahoo dot ca>
- To: <gcc at gcc dot gnu dot org>
- Date: Tue, 21 May 2002 13:39:35 -0400
- Subject: va_list question
First off, I hope this isn't off topic here.
Is the code below supposed to work in general? I mean regardless of the
compiler/platform (although the compiler used is gcc):
void f1 (const char *format, ...)
{
int i=0;
va_list args;
va_start (args, format);
f2 (format, (va_list *)args);
i = va_arg (args, int);
va_end (args);
}
void f2 (const char *format, va_list * arg)
{
int j = va_arg (*arg, int);
}
My main point of worry is type casting 'arg' to 'va_list *' and then calling
*arg inside f2.
Specially that in gcc for ppc (now I can talk about compiler/platform)
va_list is an array.
Using gcc.2.95.3 the above code crashes. However, when I change it to :
void f1 (const char *format, ...)
{
int i=0;
va_list args;
va_start (args, format);
f2 (format, args); <======
i = va_arg (args, int);
va_end (args);
}
void f2 (const char *format, va_list arg)
{
va_list ap;
__va_copy (ap, arg);
int j = va_arg (ap, int);
}
Things seem to work ok. Although I beleive va_copying shouldn't be
necessary. This should work as well.
void f2 (const char *format, va_list arg)
{
int j = va_arg (arg, int);
}
-B