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?
The
-g
flag doesn't affect the operation ofassert
, it just ensures that various debugging symbols are available.Setting
NDEBUG
is the standard (as in official, ISO standard) way of disabling assertions.You can either disable assertions completely by
or you can set NDEBUG (via -DNDEBUG) in your makefile/build procedure depending on whether you want a productive or dev version.
Use
#define NDEBUG
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.Yes, define
NDEBUG
on the command line/build system with the preprocessor/compiler option-DNDEBUG
.This has nothing to do with the debugging info inserted by
-g
.