acenv.h中有:
#ifndef va_arg
#ifndef _VALIST
#define _VALIST
typedef char *va_list;
#endif /* _VALIST */
/*
* Storage alignment properties
*/
#define _AUPBND (sizeof (acpi_native_int) - 1)
#define _ADNBND (sizeof (acpi_native_int) - 1)
/*
* Variable argument list macro definitions
*/
#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
#define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T, _AUPBND))) - (_bnd (T,_ADNBND))))
#define va_end(ap) (void) 0
#define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (_bnd (A,_AUPBND))))
#endif /* va_arg */
網上找到的2個例子:
//vstart.c
#include <stdio.h>
#include <strings.h>
#include <stdarg.h>
int demo(char *fmt, ...);
int main()
{
demo("DEMO", "This", "is", "a", "demo!", "");
return 0;
}
int demo( char *fmt, ... )
{
va_list argp;
int argno = 0;
char *para;
va_start(argp, fmt);
while (1)
{
para = va_arg(argp, char *);
if (strcmp( para, "") == 0)
break;
printf("Parameter #%d is: %s/n", argno, para);
argno++;
}
va_end( argp );
return 0;
}
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
int foo(char *fmt, ...);
int main()
{
char *a = "ast";
int b = 224;
char c = 'x';
foo("%s,%d,%c/n",a,b,c);
return 0;
}
int foo(char *fmt, ...)
{
va_list ap;
int d;
char c, *s;
va_start(ap, fmt);
while (*fmt)
switch(*fmt++)
{
case 's': /* string */
s = va_arg(ap, char *);
printf("string %s/n", s);
break;
case 'd': /* int */
d = va_arg(ap, int);
printf("int %d/n", d);
break;
case 'c': /* char */
/* need a cast here since va_arg only
takes fully promoted types */
c = (char) va_arg(ap, int);
printf("char %c/n", c);
break;
}
va_end(ap);
return 0;
}
跑一下試試吧!