DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

assert(S-osr5)


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), information is written to stderr about the call that failed and abort(S-osr5) 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-osr5), 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 .
© 2005 System Services (S-osr5)
SCO OpenServer Release 6.0.0 -- 02 June 2005