如何在 C++ 中关闭 ASSERT( x )?

发布于 2024-08-20 17:39:47 字数 95 浏览 4 评论 0原文

我怀疑某些断言代码有副作用。我想关闭 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不奢求什么 2024-08-27 17:39:47

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

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

这会重新定义断言宏,以便它扩展为空。

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)

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

对你再特殊 2024-08-27 17:39:47

如果您的意思是 assert,那么应该使用 NDEBUG 宏来控制。

If you mean assert, then that should be controlled with the NDEBUG macro.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文