_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


基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30