#include<stdio.h>
#include<stdarg.h>
#include <memory.h>
void fun2(int start,va_list ap);
void simple_va_fun(int start,...)
{
va_list arg_ptr;
int nArgValue = start;
int nArgCount = 0;
va_start(arg_ptr,start);
fun2(start,arg_ptr);
va_end(arg_ptr);
return;
}
void fun2(int start,va_list ap)
{
int nArgValue = start;
int nArgCount = 0;
do
{
++nArgCount;
printf("the %d the arg:%d/n",nArgCount,nArgValue);
nArgValue = va_arg(ap,int);
}
while (nArgValue != -1);
}
main()
{
simple_va_fun(100,200,-1);
simple_va_fun(777,888,999,67567,45678,3245,-1);
}
以上代码在fedora13下运行通过:
zxr@localhost/mnt/hgfs/linuxtmp/src/tstVa_list$./a.out
the 1 the arg:100
the 2 the arg:200
the 1 the arg:777
the 2 the arg:888
the 3 the arg:999
the 4 the arg:67567
the 5 the arg:45678
the 6 the arg:3245
zxr@localhost/mnt/hgfs/linuxtmp/src/tstVa_list$