什么是用于(在不同的平台)的NDEBUG preprocessor宏? [英] What is the NDEBUG preprocessor macro used for (on different platforms)?
问题描述
我感兴趣的是什么样的目的不同平台/编译器(实现)/框架分配给在 C 和C ++ preprocessor宏 NDEBUG
。
I'm interested in what purpose various platforms / compilers ("implementations") / frameworks assign to the the C and C++ preprocessor macro NDEBUG
.
在 C 以及C ++标准只提及这个定义一次,即控制在断言的)行为(
宏。
The C as well as the C++ standard only mention this definition once, namely to control the behavior of the assert()
macro.
我要问,只包括具体的答案,在这里你的知道的某一个平台/框架/ C 或C ++库使用 NDEBUG
定义启用或除了定义的标准禁用别的 断言()
宏
I would ask to include only specific answers, where you know that a certain platform / framework / library for C or C++ uses the NDEBUG
definition to enable or disable anything else in addition to the standard defined assert()
macro.
有关问这个问题的一个原因一直是MS(可视化-C ++)总是(?)用他们的 _DEBUG
定义和调试区分释放的东西,我想知道,这是一种常见的实践库/平台,让他们自己的定义调试还是其他库/平台上使用 NDEBUG
为他们调试相关的东西。
One reason for asking this question has been that MS (Visual-C++) always(?) uses "their" _DEBUG
define to distinguish between debug and release stuff and I was wondering if this is a common practice for a library / platform to have their "own" debug define or whether other libraries / platforms use NDEBUG
for their debug related stuff.
推荐答案
这是到有问题的框架的维护者(S)的决定。因为这样的决定有可能发生变化,这没有什么,你应该的依赖的上。我使用NDEBUG作为一切调试相关的(例如跟踪输出)切换,但我可能会改变我的脑海中的下一个版本。没有回答任何人都可以给这里是检查,你在给定的项目中使用框架的API文档的替代品。
That is a decision up to the maintainer(s) of the framework in question. Since such decisions are subject to change, it's nothing you should rely on. I use NDEBUG as a toggle for everything debug-related (e.g. trace outputs), but I might change my mind in the next release. No answer anyone could give here is a replacement for checking the API documentation of the frameworks you use in a given project.
话虽这么说,在图书馆/框架头使用NDEBUG,为别的的但的断言()
,将是一个相当愚蠢的设计决策。应用程序员的明确的允许设置/取消NDEBUG但他认为合适的,之前和/或包括任何库或框架的头后,这样的lib /框架维护者不能依靠NDEBUG被设置为释放lib或不设置调试库。我怀疑任何显著项目将有NDEBUG依赖的方式。
That being said, using NDEBUG in library / framework headers, for anything else but assert()
, would be a rather dumb design decision. The application programmer is explicitly allowed to set / unset NDEBUG however he sees fit, before and / or after including the headers of any library or framework, so the lib / framework maintainer could not rely on NDEBUG being set for a release lib or not set for a debugging lib. I doubt any significant project would have relied on NDEBUG that way.
这篇关于什么是用于(在不同的平台)的NDEBUG preprocessor宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!