A runtime assertion checks a Boolean condition during execution at a point where the condition is expected to hold. In C, assert accepts dynamic expressions; when NDEBUG is defined during compilation, the expression is not evaluated. section 8.7
A failed assertion
A gcd implementation can assert a condition that should hold on every execution. If it fails, execution produces a diagnostic such as “assertion failed in file euclid.h, function gcd2(), line 6” and calls abort. section 8.7
Use runtime assertions to:
- Expose false assumptions about variable values during debugging. section 8.7
- Disable assertion evaluation and abort calls in production compilations with NDEBUG. section 8.7
