Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#define MY_PRINT(_format, ...) printf("MIME : %s" _format, __FUNCTION__, __VA_ARGS__);
我想"\n在打印消息的末尾添加“。
"\n
但,
#define MY_PRINT_LN(_format, ...) MY_PRINT(_format "\n", ...)
有编译错误。如何...在定义宏中传递参数?
...
您使用__VA_ARGS__:
__VA_ARGS__
#define MY_PRINT_LN(_format, ...) MY_PRINT(_format "\n", __VA_ARGS__)
这是从 C99 开始标准化的。
不过,如果没有参数,最后会有一个多余的逗号。没有标准解决方案,但 GCC(可能还有其他编译器)提供了一个扩展:
#define MY_PRINT_LN(_format, ...) MY_PRINT(_format "\n", ## __VA_ARGS__)
使用 extra ##,如果没有参数,则删除最后的逗号。
##