【发布时间】:2021-11-20 17:00:11
【问题描述】:
我有一个名为foo 的函数,该函数采用...,我想将传入... 的所有参数传递给名为oof 的函数,示例代码:
#include <stdio.h>
#include <stdarg.h>
void oof(FILE * f, const char * fmt, ...){
va_list args;
va_start(args, fmt);
vfprintf(f, fmt, args);
va_end(args);
}
void foo(const char * fmt, ...){
oof(stdout, fmt, ...); // how can I pass the 3 dots?
// do other things in the function block
}
int main(int argc, char *argv[]){
foo("Hello %s\n", "World");
}
我不想传递给oof va_list,而是参数本身
【问题讨论】:
-
你没有通过三个点。它们表示函数声明中的可变数量的参数。
-
几乎不可能自己传递参数。这是question 15.12 中的C FAQ list。
-
如果
foo是一个宏,就有办法做到这一点。 -
为什么不想将
va_list传递给oof?鉴于您发布的内容,这将是处理它的正确方法。
标签: c function c-preprocessor