COHERENT manpages

This page displays the COHERENT manpage for assert() [Check assertion at run time].

List of available manpages
Index


assert() -- Macro Diagnostics (assert.h)

Check assertion at run time
#include <assert.h>
void assert(outcome)
int outcome;

assert() checks  the value of outcome,  which usually is the  product of an
expression.  If outcome is false  (zero), assert() sends a message into the
standard-error stream  and calls exit(). It is useful  for verifying that a
necessary condition is true.

The error message includes the text  of the assertion that failed, the name
of the  source file,  and the  line within the  source file that  holds the
expression in question.   These last two elements consist, respectively, of
the values of the preprocessor macros _ _FILE_ _ and _ _LINE_ _.

assert() calls exit(), which never returns.

To turn off assert(), define the macro NDEBUG prior to including the header
assert.h. This forces assert() to be redefined as

    #define assert(ignore)

See Also

exit(),
assert.h,
C preprocessor,
ANSI Standard, §7.2.1.1
POSIX Standard, §8.1

Notes

The ANSI Standard  requires that assert() be implemented as  a macro, not a
library function.  If a program suppresses the macro definition in favor of
a function call, its behavior is undefined.

Turning off  assert() with the macro  NDEBUG will affect the  behavior of a
program if the expression being evaluated normally generates side effects.

assert() is  useful for debugging, and for  testing boundary conditions for
which more graceful error recovery has not yet been implemented.