Open main menu

Wikibooks β

C Programming/C Reference/assert.h/assert

< C Programming‎ | C Reference‎ | assert.h


#include <assert.h>
void assert(expression);

Return valueEdit

The assert macro returns a void, i.e. no value.


The behaviour of the assert macro depends on the value of the NDEBUG macro. See assert.h for more details.

If NDEBUG is defined then the macro assert, regardless of argument, is defined as

#define assert(expression)        ((void) 0)

If NDEBUG is not defined the assert macro acts as a diagnostic test. If the expression argument of the macro is false (see C Programming/Control), then the macro expands to a statement which writes the text of the argument, the present file name, line number and function name to the standard error stream. Finally the assert macro calls the abort() function.

Each time the assert.h header is included the assert macro is redefined depending on the value of NDEBUG.