<分区>
我想创建一个宏来打印一些信息,并在需要时采用任意数量的参数来打印其他消息。
这是我正在谈论的代码片段:
#include <stdio.h>
#define print(msg, ...) \
printf("Line: %d File %s "## msg, __LINE__ , __FILE__, __VA_ARGS__);
int main()
{
print("Msg: %d", 13);
print("Msg: %d, Msg2: %d", 123, 234);
}
这是我遇到的一个错误:
main.cpp:12:9: error: pasting ""Line: %d File %s "" and ""Msg: %d"" does not give a valid preprocessing token
printf("Line: %d File %s "## msg, __LINE__ , __FILE__, __VA_ARGS__);
我做错了什么?