1ASSERT(3) Linux Programmer's Manual ASSERT(3)
2
3
4
6 assert - abort the program if assertion is false
7
9 #include <assert.h>
10
11 void assert(scalar expression);
12
14 If the macro NDEBUG was defined at the moment <assert.h> was last
15 included, the macro assert() generates no code, and hence does nothing
16 at all. Otherwise, the macro assert() prints an error message to stan‐
17 dard error and terminates the program by calling abort() if expression
18 is false (i.e., compares equal to zero).
19
20 The purpose of this macro is to help the programmer find bugs in his
21 program. The message "assertion failed in file foo.c, function
22 do_bar(), line 1287" is of no help at all to a user.
23
25 No value is returned.
26
28 POSIX.1-2001, C89, C99. In C89, expression is required to be of type
29 int and undefined behavior results if it is not, but in C99 it may have
30 any scalar type.
31
33 assert() is implemented as a macro; if the expression tested has side-
34 effects, program behaviour will be different depending on whether NDE‐
35 BUG is defined. This may create Heisenbugs which go away when debug‐
36 ging is turned on.
37
39 abort(3), assert_perror(3), exit(3)
40
41
42
43C99 2002-08-25 ASSERT(3)