Standard C Libraries -. More...
Go to the source code of this file.
Functions | |
void | assert (int expression) |
Standard C Libraries -.
The header file, assert.h, consists of a single macro that is useful for debugging logic errors in programs. By using the assert statement in critical locations where certain conditions should be true, the logic of the program may be tested. Assertion testing may be turned off without removing the code by defining NDEBUG before including <assert.h>. If the macro NDEBUG is defined, assert() is ignored and no code is generated.
The documentation in this header file has been copied from the documentation provided with the Microchip MPLAB XC16 compiler. The original license agreement included with the XC16 compiler applies!
void assert | ( | int | expression) |
Description: If the expression is false, an assertion message is printed to stderr and the program is aborted.
Include: <assert.h>
expression | The expression to test. |
Remarks:
The expression evaluates to zero or non-zero. If zero, the assertion fails, and a message is printed to stderr. The message includes the source file name (FILE), the source line number (LINE), the expression being evaluated and the message. The macro then calls the function abort(). If the macro _VERBOSE_DEBUGGING is defined, a message will be printed to stderr each time assert() is called.
Example:
Output:
sampassert.c:9 a == 6 – assertion failed
ABRT
with _VERBOSE_DEBUGGING defined:
sampassert.c:8 a == 4 – OK
sampassert.c:9 a == 6 – assertion failed
ABRT