且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

_DEBUG vs NDEBUG

更新时间:2023-11-14 09:34:22

Visual Studio定义 _DEBUG 您指定 / MTd / MDd 选项, NDEBUG 禁用标准C断言。如果您希望调试代码与 _DEBUG 库/ zh712wwf%28VS.80%29.aspxrel =noreferrer> MS CRT调试技术 NDEBUG 如果要与 assert()



如果您定义自己的调试宏(而且您不会破解编译器或C运行时)避免使用下划线启动名称,因为这些保留。


Which preprocessor define should be used to specify debug sections of code?

Use #ifdef _DEBUG or #ifndef NDEBUG or is there a better way to do it, e.g. #define MY_DEBUG?

I think _DEBUG is Visual Studio specific, is NDEBUG standard?

Visual Studio defines _DEBUG when you specify the /MTd or /MDd option, NDEBUG disables standard-C assertions. Use them when apropriate, 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().

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.