管理调试信息
一种方式:
#define __DEBUG #ifdef __DEBUG printf(xxx); #endif
缺点是:每条输出语句都被两条语句包围着
另一种方式:
#ifdef __DEBUG #define DEBUG(info) printf(info) #else #define DEBUG(info) #endif
缺点:printf是支持多个参数的,且参数不定
//============================================================================
// Name : debug.cpp
// Author : boyce
// Version : 1.0
// Copyright : pku
// Description : Hello World in C++, Ansi-style
//============================================================================
#include "debug.h"
#define __DEBUG__
#ifdef __DEBUG__
#define DEBUG(format,...) printf("File: "__FILE__", Line: %05d: "format"\n", __LINE__, ##__VA_ARGS__)
#else
#define DEBUG(format,...)
#endif
int main() {
char str[]="Hello World";
DEBUG("A ha, check me: %s",str);
return 0;
}
输出:
File: applications\main.c, Line: 00191: A ha, check me: Hello World
参考文章:地址
如果,感到此时的自己很辛苦,那告诉自己:容易走的都是下坡路。坚持住,因为你正在走上坡路,走过去,你就一定会有进步。如果,你正在埋怨命运不眷顾,开导自己:命,是失败者的借口;运,是成功者的谦词。命运从来都是掌握在自己的手中,埋怨,只是一种懦弱的表现;努力,才是人生的态度。

浙公网安备 33010602011771号