//----------------------------------------------
#include <stdio.h>
#define DEBUG 1
#if DEBUG
#define myDebug(fmt, ...) printf("[fun:%s - line:%d] " fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define myDebug(fmt, ...)
#endif
在头文件中添加定义即可
#include <stdio.h>
#define DEBUG 1
#if DEBUG
#define myDebug(fmt, ...) printf("[fun:%s - line:%d] " fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define myDebug(fmt, ...)
#endif
本文介绍了如何在C程序中通过预处理器宏DEBUG实现代码的条件编译,当DEBUG为真时,myDebug函数会输出函数名和行号,便于调试。
7万+

被折叠的 条评论
为什么被折叠?



