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.

Functions

void assert (int expression)
 

Detailed Description

Standard C Libraries -.

Compiler:
MPLAB XC16 compiler

Description

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>

Parameters
expressionThe 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:

#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
}

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