_DEBUG 与 NDEBUG

_DEBUG vs NDEBUG(_DEBUG 与 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)