symbian 下 不定参数的函数

e32def.h contains the va_list, va_start and va_end macros.

// Definition
int math (const OperatorType ty ...)
{
va_list ap; // param list
va_start(ap,ty); // where to start in the list i.e. after ty
int x = va_arg(ap,int); // go through the parameters, which are ints
int res = 0;
while (0!=x) // while not zero
{
switch (ty)
{
case ADD: // other cases, e.g. SUBTRACT, not used
default:
res+=x;
}
x = va_arg(ap,int); // Get next param
}
va_end(ap); // clean up the stack frame
return res;
}
// Called
int r = math(ADD,1,2,3,4,5);

你可能感兴趣的:(UP,Go,Symbian)