assert(S) 6 January 1993 assert(S) Name assert - verify program assertion Syntax #include <assert.h> void assert (expression) int expression; Description The assert macro is inserted into a program to cause it to fail if an event occurs. This macro is used to debug a program. assert tests expression and if the expression is false (compares equal to zero), in- formation is written to stderr about the call that failed and abort(S) is called to stop execution of the program. The information written to stderr is in the form: Assertion failed: expression, file xyz, line nnn Where, xyz is the name of the source file and nnn the source line number of the assert statement. The name of the source file is taken from the FILE preprocessing macro, and the source file line number is taken from the LINE preprocessing macro. Assertions can be stopped from being compiled into the program by: 1. Compiling with the -DNDEBUG preprocessor option See cpp(CP). 2. Inserting the #define NDEBUG preprocessor control statement before the #include <assert.h> statement Diagnostics No return values or errors are defined. See also abort(S), cpp(CP) Notes If the macro KR is defined, then assert is implemented as a macro. This macro places the expression into a string using quotation marks thus if the expression contains a string literal, the statement will not compile. Standards conformance assert is conformant with: X/Open Portability Guide, Issue 3, 1989; and ANSI X3.159-1989 Programming Language -- C.