Tuesday, October 26, 2010


assert() is a macro that is sometimes used by 'Design by Contract (DoC)' programming, where code tests, preconditions, invariants, and postconditions.

assert() is defined in <assert.h> and <cassert>.

It is enabled via 'DEBUG' compiler macro and code #defines, and is disabled by the 'NDEBUG' compiler macro and code #define.

It is disabled by default.

The function basically asserts that the enclosed statement is true (or evaluates to a non-zero value).

When using asserts(), you want to make sure that you do not enclose any code that includes side effects, or else your code will behave differently depending on whether DEBUG is enabled or not.

No comments:

Post a Comment