Pat*_*cia 1 c++ debugging logging c-preprocessor
如果DEBUG已定义,我想跟踪我的代码,如下面的#ifdef代码块所示:
#ifdef DEBUG
OP_LOG(debug) << "SEQUENCE: " __FILE__ << "::" << __FUNCTION__;
#endif
Run Code Online (Sandbox Code Playgroud)
有人说我可以使用a,#define以便上面三行只是一行代替.这是我能够找到它的最接近的,但无论是否DEBUG定义,它都无条件地提供跟踪输出:
#define DEBUG_TRACE(note) OP_LOG(debug) << "SEQUENCE : " << __FILE__ <<"::" <<__FUNCTION__ << note
Run Code Online (Sandbox Code Playgroud)
我不知道怎么做条件#define.这是可能的,如果是的话,该怎么做?
你不能把#ifdef在的更换部件#define,但你可以使用#define 里面的#ifdef/ #endif块,就像这样:
#ifdef DEBUG
#define DEBUG_TRACE(note) ... // put your debug code here
#else
#define DEBUG_TRACE(note)
#endif
Run Code Online (Sandbox Code Playgroud)
在这种#else情况下,DEBUG_TRACE如果DEBUG未定义,则定义为展开为空.
| 归档时间: |
|
| 查看次数: |
455 次 |
| 最近记录: |