Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

assert - output diagnostic messages

&pagelevel(4)&pagelevel

Syntax

#include <assert.h>

void assert(int expression);

Description assert() is implemented as a macro. When it is executed, it checks whether expression

evaluates to false (0) at a specific position in the program. If an error occurs, assert()
writes a comment about the particular call that failed on stderr and calls abort(). The
message includes the text of the argument, the name of the source file (__FILE__), and
the source file line number (__LINE__).

Notes

assert calls are not executed if NDEBUG is defined. This can be done by the following
methods:

  • by specifying a preprocessor option when calling the compiler (see the manuals "C
    Compiler" [3 (Related publications)] and "C/C++ Compiler" [4 (Related publications)])

  • by inserting a preprocessor control statement #define NDEBUG in the source program
    before the #include <assert.h> statement.

See also

abort(), __FILE__, __LINE__, stderr(), assert.h.