Chapter 2. Diagnostics <assert.h>

The header <assert.h> defines the assert macro and refers to another macro.

NDEBUG

which is not defined by <assert.h>. 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 simply as

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

The assert macro is implemented as a macro, not as an actual function. If the macro definition is suppressed in order to access an actual function, the behavior is undefined.

2.1. Program Diagnostics

2.1.1. The assert macro

Synopsis
#include <assert.h>

void assert (int expression );

Description

The assert macro puts diagnostics into programs. When it is executed, if expression is false (that is, it compares equal to zero), the assert macro writes information about the particular call that failed (including the text of the argument, the name of the source file, and the source line number–the latter are respectively the values of the preprocessing macros __FILE__ and __LINE__) on the standard error file in an implementation-defined format. It then calls the abort function.

Returns

The assert macro returns no value.

See Also

Section 10.4.1, the abort function

Implementation Notes
  • The assert macro calls the library function _assert.