如何在C ++中关闭ASSERT(x)? [英] How can I turn off ASSERT( x ) in C++?

查看:443
本文介绍了如何在C ++中关闭ASSERT(x)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑某些ASSERTION代码有副作用.我想关闭ASSERT,而无需对我的代码的编译方式进行任何其他更改.我正在使用MSVS2008.从调试切换到发行版不会起作用,因为那样会改变内存的初始化方式.

I suspect some ASSERTION code is having side effects. I'd like to switch off ASSERT without making any other changes to how my code is compiled. I'm using MSVS2008. Switching from debug to release won't do as that will alter how memory is initialised.

推荐答案

在包含cassert(或包含cassert的包含)之后将其放在头文件的顶部

Put this at the top of your header files after the inclusions of cassert (or a include that includes cassert)

#undef assert
#define assert(x) ((void)0)

重新定义断言的marco,使其扩展为空.

Which redefines the assert marco so that it expands to nothing.

这篇关于如何在C ++中关闭ASSERT(x)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆