assert.h
assert
- Prototype
- void assert(expression);
- Description
- This function is useful for adding internal consistency checks. When assert is
executed it checks the expression argument and, if it is zero, displays the
following message on the standard error device, after which the program
aborts.
Assertion failure: 'expression' on line ?? in file '???'
The assert function can be deactivated by defining the macro NDEBUG prior to the inclusion of assert.h header file. The effect is that all assertions become null statements. - Return Value
- None
- Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- Example
/* Example of assert */ #include <assert.h> #include <stdio.h> #include <stdlib.h> void main() { int value; value = 3; while (value) { assert(value > 1); printf("Passed assert (%d > 1)\n", value); value--; } }
- Output
Passed assert(3 > 1) Passed assert(2 > 1) Assertion failed: value > 1, file c:\rtl\assert.c, line 13