Netcruzer  V2.02
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
assert.h File Reference

Standard C Libraries -. More...

Go to the source code of this file.


void assert (int expression)

Detailed Description

Standard C Libraries -.

MPLAB XC16 compiler


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.

Software License Agreement

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!

Function Documentation

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>

expressionThe expression to test.

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.


#include <assert.h> // for assert
int main(void) {
int a;
a = 2 * 2;
assert(a == 4); // if true-nothing prints
assert(a == 6); // if false-print message
// and abort

sampassert.c:9 a == 6 – assertion failed
with _VERBOSE_DEBUGGING defined:
sampassert.c:8 a == 4 – OK
sampassert.c:9 a == 6 – assertion failed