例如,如果我有:
#define PRINT(x) fprintf(stderr, x);
在代码中我附加了它:
PRINT(("print this"))
输出是: [打印这个]
如果我附加它:
PRINT(("print %s", "this"))
输出是: [这个]
有人能解释一下为什么它只收到“this”参数而不是整个字符串吗?
最佳答案
PRINT(("print %s", "this"))
变成:
fprintf(stderr, ("print %s", "this"));
相当于:
fprintf(stderr, "this");
However , variadic macros (来自 C99)工作:
#define PRINT(...) fprintf(stderr, __VA_ARGS__)
int main() {
PRINT("print %s", "this");
return 0;
}
关于c - 打印宏功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2628595/