Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?


2 Answers

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.

like image 157
Michael Burr Avatar answered Sep 03 '25 22:09

Michael Burr


Why not just define your own assert:

#define assert(x) MessageBox(...);
like image 35
Baiyan Huang Avatar answered Sep 03 '25 22:09

Baiyan Huang