How to put assert into release builds in C/C++

pra che picture pra che · Mar 7, 2009 · Viewed 30.7k times · Source

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?

Answer

Michael Burr picture Michael Burr · Mar 7, 2009

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()

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