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

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

2012年12月06日 09:04:45 happy803 阅读数:3906 标签: DBGlinuxLinuxLINUX 更多

个人分类: linux函数

详细内容可参考: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。

猜你喜欢

转载自blog.csdn.net/weixin_41632560/article/details/85263353