Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ assert(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

abort(S)

cpp(CP)


 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.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026