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(3) 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 behavior will be different depending on whether NDEBUG
35 is defined. This may create Heisenbugs which go away when debugging is
36 turned on.
37
39 abort(3), assert_perror(3), exit(3)
40
42 This page is part of release 3.25 of the Linux man-pages project. A
43 description of the project, and information about reporting bugs, can
44 be found at http://www.kernel.org/doc/man-pages/.
45
46
47
48GNU 2002-08-25 ASSERT(3)