問題描述
應該使用哪個預處理器定義來指定代碼的調試部分?
Which preprocessor define should be used to specify debug sections of code?
使用 #ifdef _DEBUG
或 #ifndef NDEBUG
或者有更好的方法來做到這一點,例如#define MY_DEBUG
?
Use #ifdef _DEBUG
or #ifndef NDEBUG
or is there a better way to do it, e.g. #define MY_DEBUG
?
我認為 _DEBUG
是特定于 Visual Studio 的,是 NDEBUG 標準嗎?
I think _DEBUG
is Visual Studio specific, is NDEBUG standard?
推薦答案
Visual Studio 定義 _DEBUG
當您指定 /MTd
或 /MDd
> 選項,NDEBUG
禁用標準 C 斷言.在適當的時候使用它們,即 _DEBUG
如果您希望您的調試代碼與 MS CRT 調試技術 和 NDEBUG
如果你想和 assert()
保持一致.
Visual Studio defines _DEBUG
when you specify the /MTd
or /MDd
option, NDEBUG
disables standard-C assertions. Use them when appropriate, ie _DEBUG
if you want your debugging code to be consistent with the MS CRT debugging techniques and NDEBUG
if you want to be consistent with assert()
.
如果您定義自己的調試宏(并且您不會破解編譯器或 C 運行時),請避免以下劃線開頭的名稱,因為這些是保留的.
If you define your own debugging macros (and you don't hack the compiler or C runtime), avoid starting names with an underscore, as these are reserved.
這篇關于_DEBUG 與 NDEBUG的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!