RE: va_arglist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That's all about unpacking an arglist. I need to pack an arglist. Also, the function in question isn't actually printf, but a custom API, and it doesn't have a vprintf equivalent.

-----Original Message-----
From: Harvey Chapman [mailto:hchapman-gcc-help@xxxxxxxx] 
Sent: Tuesday, December 02, 2008 7:29 AM
To: Austin, Alex
Cc: gcc-help@xxxxxxxxxxx
Subject: Re: va_arglist

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);
}



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux