_DEBUG vs NDEBUG(_DEBUG 与 NDEBUG)
问题描述
应该使用哪个预处理器定义来指定代码的调试部分?
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:_DEBUG 与 NDEBUG
基础教程推荐
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
