代码中 DEBUG 调试方法

调试代码时 可以使用 DEBUG 宏,可以方便调试。 调试好后,可以屏蔽掉 #define debug 即可关闭代码中的 DEBUG 

//#define debug
#ifdef debug
#define DEBUG(fmt,args...) \
printf( "[%s]\t\t"fmt"-- [line:%d] [func: %s]\n", "module",##args,__LINE__,__FUNCTION__)

#else
#define DBG(fmt,args...) \

#endif

##args 就等于 args... 

linux 调试时可以打印出 代码具体相关信息

printf("line : %d\n", __LINE__);                   //当前行数
printf("filename : %s\n", __FILE__);             //当前文件名
printf("function : %s\n", __FUNCTION__);  //当前函数
printf("time : %s\n", __TIME__);                  //当前时间
printf ("date : %s\n",  __DATE__);              //当前日期
输出:
line : 10
filename : test.c
function : main.c
time : 14:13:51
date : Oct 13 2012

 

 

 

posted @ 2014-07-03 13:18  00奋斗00  阅读(788)  评论(0编辑  收藏  举报