如何完全禁用断言 [英] how to completely disable assertion
问题描述
我有我的code充分调用到断言(条件)
。
在调试版本我使用 g ++的-g
利用我的说法。
随着我惊讶的是我能看到的断言也工作在我的发行版本,一个没有编制 -g
选项。
I have my code full of call to assert(condition)
.
In the debug version I use g++ -g
exploiting my assertion.
With my surprise I can see assertion working also in my release version, the one compiled without -g
option.
我怎样才能完全禁止在编译时我的说法?我应该明确定义 NDEBUG
在我产生任何的构建,尽管他们调试,发布或任何其他?
How can I completely disable at compile time my assertion? Should I explicitly define NDEBUG
in any build I produce despite they are debug,release or whatever any other?
推荐答案
您必须的#define NDEBUG
(或使用带有G ++旗-DNDEBUG),这将禁用断言为只要它包含断言头文件之前定义的。
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.
这篇关于如何完全禁用断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!