va_arglist

Harvey Chapman hchapman-gcc-help@3gfp.com
Tue Dec 2 13:30:00 GMT 2008


Maybe this will help?

http://www.cl.cam.ac.uk/cgi-bin/manpage?3+stdarg

Although, I tried nesting some printf-like calls and had no success. 
Perhaps there's a trick to it?

H.


#include <stdio.h>
#include <stdarg.h>

int testB(char *fmt, ...)
{
  va_list ap;

  va_start(ap, fmt);
  printf("%p  ", va_arg(ap, char *));
  printf("%c\n", va_arg(ap, int));
  va_end(ap);

  va_start(ap, fmt);
  vprintf(fmt, ap);
  va_end(ap);

  return(0);
}

int testA(char *fmt, ...)
{
  int rc = 0;
  va_list ap;

  va_start(ap, fmt);
  printf("%p  ", va_arg(ap, char *));
  printf("%c\n", va_arg(ap, int));
  va_end(ap);

  va_start(ap, fmt);
  rc = testB(fmt, ap);
  va_end(ap);

  return(rc);
}

int main(int argc, char *argv[])
{
  testA("Hello, %s%c\n", "World", '!');

  return(0);
}



More information about the Gcc-help mailing list