如何完全禁用对assert()的调用? [英] How can I completely disable calls to assert()?
问题描述
我的代码充满了对assert(condition)
的调用.
在调试版本中,我使用g++ -g
触发我的断言.
出乎意料的是,在我的发行版本中也触发了相同的断言,即没有-g
选项编译的断言.
My code is full of calls to assert(condition)
.
In the debug version I use g++ -g
which triggers my assertions.
Unexpectedly, the same assertions are also triggered in my release version, the one compiled without -g
option.
如何在编译时完全禁用我的断言?我应该在生成的任何生成中明确定义NDEBUG
,而不管它们是调试,发布还是其他任何形式?
How can I completely disable my assertions at compile time? Should I explicitly define NDEBUG
in any build I produce regardless of whether they are debug, release or anything else?
推荐答案
您必须#define NDEBUG
(或将-DNDEBUG
标志与 g ++ 一起使用),这将禁用断言,前提是之前已定义包含断言头文件.
You must #define NDEBUG
(or use the flag -DNDEBUG
with g++) this will disable assert as long as it's defined before the inclusion of the assert header file.
这篇关于如何完全禁用对assert()的调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!