Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The assert() macro is a convenient mechanism for incorporating diagnostic tests in code (see MSC11-C, “Incorporate diagnostic tests using assertions”). Expressions used with the standard assert macro should not have side effects. Typically, the behavior of the assert macro depends on the status of the NDEBUG preprocessor symbol. If NDEBUG is undefined, the assert macro is defined to evaluate its expression argument and abort if the result of the expression is convertible to false. If NDEBUG is defined, assert is defined to be a no-op. Consequently, any side effects resulting from evaluation of the expression in the assertion are lost in non-debugging versions of the code.
Because assert is a macro, this rule is a special case of PRE31-C, “Never invoke an unsafe macro with arguments containing assignment, increment, decrement, volatile access, or function call.”