相关疑难解决方法(0)

令牌贴在C中

看完VA_NARG后

我尝试使用宏根据C中的参数数量实现函数重载.现在的问题是:

void hello1(char *s) { ... }
void hello2(char *s, char *t) { ... }
// PP_NARG(...)           macro returns number of arguments :ref to link above
 // does not work
#define hello(...)         hello ## PP_NARG(__VA_ARGS__)  

int main(void)
{
   hello("hi");   // call hello1("hi");
   hello("foo","bar"); // call hello2("foo","bar");
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

我从C-faq那里读到了这个.但仍然无法让它工作......

c c99 stringification c-preprocessor variadic-macros

6
推荐指数
1
解决办法
1773
查看次数