开发者

assert, -NDEBUG and segmentation fault

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开发者_JS百科 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜