assert

Identifies program logic errors

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Platform:NLM
Service:Debug

Syntax

  #include <assert.h> 
    
  void assert  (  
     int   expression);
  

Parameters

expression

(IN) Specifies an expression to test assertion.

Return Values

assert returns no values. Because assert uses the printf function to display errors, errno can be set when an output occurs.

Remarks

assert prints a diagnostic message upon the stderr stream and terminates the program if expression is FALSE (0). The diagnostic message has the following form:

     Assertion failed: expression, file filename, line  
     linenumber
  

The filename and linenumber variables are defined as follows:

filename

Specifies the name of the source file.

linenumber

Specifies the line number of the assertion that failed in the source file.

The filename and linenumber values are the values of the preprocessing macros __FILE__ and __LINE__, respectively. No action is taken if expression is TRUE (nonzero).

The given expression should be chosen so that it is true when the program is functioning as intended. After the program has been debugged, the special "no debug" identifier NDEBUG can be used to remove assert functions from the program when it is recompiled. If NDEBUG is defined (with any value) with a -d command line option or with a #define directive, the C preprocessor ignores all assert functions in the program source.