<tt>void assert(int status)</tt>




Document: The C Standard Library

next Character Class Tests: ctype.h
up Diagnostics: assert.h
gif Diagnostics: assert.h

void assert(int status)

For technical reasons, this object is not implemented as a function in the normal sense, but is what is called a macro instead. However, for most practical purposes, it can be regarded just as any "normal" function.

If status is non-zero then assert() will have no effect; but if status is zero then a message of the following form will be output to stderr:

Assertion failed: status, file filename, line nnn
where status is the value of status (i.e. zero), filename is the name of the source file containing the call to assert(), and nnn is the line number in that file at which the call appears. assert() then causes the program to terminate.

assert() is potentially a very useful way of dealing with error or exception conditions detected within your programs, where the condition is such that you are unable (or unwilling) to try to make the program deal with it in any more "intelligent" way. The beauty of assert() is that, if it is activated, the resulting message immediately pinpoints exactly the position in your source code where the problem is detected. However, note that this benefit will be almost totally lost if you place the invocation of assert() within a function of your own, which you then call from wherever the exception is detected: for then the file name and line number output by assert() will always be the same (namely within your exception handler) and will not give any indication of the "real" position at which the problem was detected.




Document: The C Standard Library

next Character Class Tests: ctype.h
up Diagnostics: assert.h
gif Diagnostics: assert.h



McMullin@eeng.dcu.ie
Fri Mar 29 14:35:38 GMT 1996