man pages section 3: Basic Library Functions

Exit Print View

Updated: July 2014
 
 

assert(3C)

Name

assert - verify program assertion

Synopsis

#include <assert.h>

void assert(int expression);

Description

The assert() macro inserts diagnostics into applications. When executed, if expression is FALSE (zero), assert() prints the error message

Assertion failed: expression, file xyz, line nnn

on the standard error output and aborts. In the error message, xyz is the name of the source file and nnn the source line number of the assert() statement. These are respectively the values of the preprocessor macros __FILE__ and __LINE__.

Since assert() is implemented as a macro, the expression may not contain any string literals.

Compiling with the preprocessor option –DNDEBUG or with the preprocessor control statement #define NDEBUG ahead of the #include <assert.h> statement, will stop assertions from being compiled into the program.

Messages printed from this function are in the native language specified by the LC_MESSAGES locale category. See setlocale(3C).

Attributes

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Safe
Standard

See Also

abort(3C), gettext(3C), setlocale(3C), attributes(5), standards(5)