当前位置: 首页 > 工具软件 > DBG > 使用案例 >

关于linux中DBG宏定义的使用总结

吴炎彬
2023-12-01

详细内容可参考:http://blog.csdn.net/songqqnew/article/details/6710634

总结:

#ifdef DEBUG   

#define DBG(...) fprintf(stderr, " DBG(%s, %s(), %d): ", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, __VA_ARGS__)  

 

#else   

#define DBG(...)   

#endif  

 

int main()  

{  

DBG("hello\n");  

}

/*C语言预处理器定义的一些宏 

__LINE__  当时行号(预处理器正在执行的那一时刻),十进制数 

__FUNCTION__ 当时函数,字符串 

__FILE__当时文件,字符串 

__DATE__当时日期,字符串 

__TIME__当时时间,字符串 

 

*/  

      如果在gcc ,use  -D define DEBUG micro

[root@localhost test]# gcc -o test1 test1.c -DDEBUG  

[root@localhost test]# ./test1   

 DBG(test1.c, main(), 11): hello   // 这行为打印的内容,后面的hello为程序DBG("hello\n");中的hello。

 类似资料: