常见的这个宏__VA_ARGS__可以方便的写一些宏函数,打印log,其中...代表传参缺省
#include <iostream>
#define error_printf(fmt,...) printf("[ERROR][MODULE_NAME](%s:%s|%d)",__FILE__,__func__,__LINE__,##__VA_ARGS__)
#define LOG(...) printf(__VA_ARGS__)
int main() {
std::cout << "Hello, World!" << std::endl;
LOG("what is this %s, it is %d ,this is file %s ,in function %s, line %d\n","my lucky number", 24, __FILE__, __func__ ,__LINE__);
error_printf("ok");
return 0;
}
其中用到很多__FILE__等宏的定义都是编译器预设值的一些宏
具体可以参考这篇文章:
C语言中的__FILE__、__LINE__和__func__等预定义跟踪调试_行者三个石的博客-CSDN博客_c语言__func__