如何在 C/C++ 中将断言放入发布版本 [英] How to put assert into release builds in C/C++

查看:28
本文介绍了如何在 C/C++ 中将断言放入发布版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要运行 ship build 并且我需要在 release build 中的某些条件下断言以查看问题是否已解决.我该怎么做?

I need to only run ship build and I need to assert on certain condition in release build to see if the problem is fixed. How do I do it?

推荐答案

取消定义 NDEBUG 宏 - 您可以围绕要保留在构建中的断言在本地执行此操作:

Undefine the NDEBUG macro - you can do this locally around the asserts you want to remain in the build:

#undef NDEBUG
#include <assert.h>   // reinclude the header to update the definition of assert()

或者做任何你需要做的事情,这样你的构建过程就不会首先定义 NDEBUG 宏.

or do whatever you need to do so your build process does not define the NDEBUG macro in the first place.

这篇关于如何在 C/C++ 中将断言放入发布版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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