Abruzzo Forte e Gentile Abruzzo Forte e Gentile - 22 days ago 7
C Question

how to completely disable assertion

I have my code full of call to

assert(condition)
.
In the debug version I use
g++ -g
exploiting my assertion.
With my surprise I can see assertion working also in my release version, the one compiled without
-g
option.

How can I completely disable at compile time my assertion? Should I explicitly define
NDEBUG
in any build I produce despite they are debug,release or whatever any other?

GWW GWW
Answer

You must #define NDEBUG (or use the flag -DNDEBUG with g++) this will disable assert as long as it's defined before the inclusion of the assert header file.

Comments