va_arglist
Austin, Alex
Alex.Austin@spectrumdsi.com
Tue Dec 2 15:39:00 GMT 2008
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@3gfp.com]
Sent: Tuesday, December 02, 2008 7:29 AM
To: Austin, Alex
Cc: gcc-help@gcc.gnu.org
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);
}
More information about the Gcc-help
mailing list