Main index | Section 3 | 日本語 | Deutsch | Options |
#include <assert.h>
If expression is true, the assert() macro does nothing.
The
assert()
macro
may be removed at compile time by defining
NDEBUG
as a macro
(e.g., by using the
cc(1)
option
The assert() macro should only be used for ensuring the developer's expectations hold true. It is not appropriate for regular run-time error detection.
assert(1 == 0);
generates a diagnostic message similar to the following:
Assertion failed: (1 == 0), function main, file main.c, line 100.
The following assert tries to assert there was no partial read:
assert(read(fd, buf, nbytes) == nbytes);
However, there are two problems. First, it checks for normal conditions, rather than conditions that indicate a bug. Second, the code will disappear if NDEBUG is defined, changing the semantics of the program.
ASSERT (3) | May 31, 2018 |
Main index | Section 3 | 日本語 | Deutsch | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | Unix is a junk OS designed by a committee of PhDs. | ” |
— Dave Cutler |