我看到此链接Passing variable arguments to another function that accepts a variable argument list。还将其传递给宏的语法是什么?
#include <stdarg.h>
#define exampleW(int b, args...) function2(b, va_args)
static void exampleV(int b, va_list args);
void exampleB(int b, ...)
{
va_list args;
va_start(args, b);
exampleV(b, args);
//also pass args to a macro which takes multiple args after this step
??? [Is it exampleW(b, ##args)]
va_end(args);
}
static void exampleV(int b, va_list args)
{
...whatever you planned to have exampleB do...
...except it calls neither va_start nor va_end...
}
这是不可能的。宏是在编译时扩展的,因此需要在编译时使用宏的位置知道它们的参数。通常在运行时才知道函数exampleB
的参数。即使在很多情况下,在编译函数调用时可能都知道参数,但参数可能位于其他源文件中,这对您使用此源文件中的宏没有帮助。