I have quite a large piece of code, that works well in a development version, with many assert() in the code. I disabled assertions with -DNDEBUG directive passed to g++, and now my code breaks with seg. fault. Is there something I don't know about assert()?
The most common issue with assert to my knowledge is having code with side effects within the assert itself. When you compile with -DNDEBUG asserts are essentially commented out, and thus code inside the assert isn't executed. The assert man page mentions this in the bugs section:
BUGS
assert() is implemented as a macro; if the expression tested has side-
effects, program behavior will be different depending on whether NDEBUG
is defined. This may create Heisenbugs which go away when debugging is
turned on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With