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

assert allows you to place assertions and diagnostic tests into programs.

If NDEBUG is defined as a macro name at the point in the source file where <assert.h> is included, the assert macro is defined as:

#define assert(ignore) ((void)0)

If NDEBUG is not defined as a macro name at the point in the source file where <assert.h> is included, the assert macro expands to a void expression that calls __assert. When such an assert is executed and expression is false, assert calls the __assert function with information about the particular call that failed: the text of the argument, the name of the source file, and the source line number. These are the stringized expression and the values of the preprocessing macros __FILE__ and __LINE__.

The prototype for __assert is:

extern void __assert(const char *, const char *, int);

There is no default implementation of __assert. Keeping __assert out of the library means that you can can customize its behaviour without rebuilding the library.

Important notes

The assert macro is redefined according to the current state of NDEBUG each time that <assert.h> is included.

Portability

assert conforms to ISO/IEC 9899:1990 (C90).