使用VS实现C/C++ Debug函数(宏)
2023-07-29 16:18 作者:R_X_offical | 我要投稿
参考了网上的现成案例,使用自带的__FILE__等宏,实现debug函数。(rx前缀为个人标识)
__FILE__默认会包含代码文件的绝对路径。如果要去掉路径,需要修改设置。

#ifndef _RX_DebugBasic_H_
#define _RX_DebugBasic_H_
//是否开启debug打印 包含_RX_DEBUG_则开启debug打印,反之关闭
#ifdef _RX_DEBUG_
const unsigned int RX_DEBUG_FLAG = true;
#else
const unsigned int RX_DEBUG_FLAG = false;
#endif // _RX_DEBUG_
#include"RX_NormalStdBasic.h"//此处替换成stdio.h或者包含stdio.h的文件
#define rx_debug(argc,...) \
do{ \
if(true == RX_DEBUG_FLAG) \
{ \
printf("\r\nRX_debug[file:%s][func:%s][line:%d]=> ", __FILE__, __func__, __LINE__); \
printf(argc, ##__VA_ARGS__); \
} \
}while(0)
#endif // !_RX_DebugBasic_H_
去除文件名的路径


实际效果:

输出:
