This is the mail archive of the gcc@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]

Calling va_start multiple times vs __va_copy



Is it legitime to parse the optional arguments in a variadic function
multiple times _without_ copying the va_list through (__)va_copy ?

I mean a situation like this one:

void foo( int argno, ... )
  {
     va_list ap;

     va_start(ap, argno);
     /* parse arguments through va_arg */
     va_end(ap);

     va_start(ap, argno);
     /* parse arguments again */
     va_end(ap);
  }

With GCC, that works - but is that against the standards ?

Some documentations recommend to copy the va_list after initializing it
instead of initializing it multiple times:

/* [...] */

va_list ap, ap2;

va_start(ap, argno);
__va_copy(ap2, ap);
/* parse arguments of ap through va_arg */
va_end(ap);

/* parse arguments of ap2 through va_arg */
va_end(ap2);

*/ [...] */

Well, the second one seems more logical - but is the first one
standard-confirming ?
Can a va_list be started multiple times through va_start ?

But, __va_copy does not belong to the ISO standard, right ? 
And a direct assigment of two va_list variables would be not possible, too
?

So isn't the second example non-standard confirming ?


Thanks for any explanations,

Sebastian Ude


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