#define DEBUG 用法

#define DEBUG用来简化调试和版本发布,当开启debug模式,在程序首行加入这行代码即可。当需要发布版本时,去除debug输出信息,只需要注释掉这行代码。

#define DEBUG
main()
{
#ifdef DEBUG
    printf("Debugging\n");
#else
    printf("Not debugging\n");
#endif
    printf("Running\n");
}


或者

#ifdef DEBUG
#define DBG(x) do{x;}while(0)
#else
#define DBG(x)
#endif


用的时候写为DBG(printf("Debugging\n")即可。


Reference

[1].http://blog.163.com/m13591120447_1/blog/static/2163791892013127104854730/?COLLCC=1999350648

你可能感兴趣的:(#define DEBUG 用法)