【发布时间】:2011-07-31 00:05:35
【问题描述】:
我有一个函数,它接受可变数量的参数。我想从这个函数中调用具有固定数量参数的函数,
void log(int level, const char* format, ...)
{
va_list args;
va_start(args, fmt);
int count = 0;
void *navigator[10] = NULL;
while ((navigator[count] = va_arg(args, char*) ) != NULL && count < 10)
++count; //Is this the right way to count no. of arguments passed ?
fprintf(stderr, "**** No of arguments : %d\n", count);
fflush(stderr);
switch (count - 2)
{
case 0:
log_l(level, fmt);
break;
case 1:
log_l1(level, fmt, navigator[0]); // how would I get arg1 here,
// I get NULL in the called function)*/
break;
.
.
.
.
.
};
}
我想知道计算传递的参数数量的正确方法,然后正确地将它们转发给其他固定参数函数。
【问题讨论】: