1ASSERT(3)                  Linux Programmer's Manual                 ASSERT(3)
2
3
4

NAME

6       assert - abort the program if assertion is false
7

SYNOPSIS

9       #include <assert.h>
10
11       void assert(scalar expression);
12

DESCRIPTION

14       This  macro can help programmers find bugs in their programs, or handle
15       exceptional cases via a crash that will produce limited debugging  out‐
16       put.
17
18       If  expression is false (i.e., compares equal to zero), assert() prints
19       an error message to standard error and terminates the program by  call‐
20       ing  abort(3).   The  error  message  includes the name of the file and
21       function containing the assert() call, the source code line  number  of
22       the call, and the text of the argument; something like:
23
24           prog: some_file.c:16: some_func: Assertion `val == 0' failed.
25
26       If  the  macro  NDEBUG  is  defined  at  the moment <assert.h> was last
27       included, the macro assert() generates no code, and hence does  nothing
28       at  all.   It  is not recommended to define NDEBUG if using assert() to
29       detect error conditions since the software may behave non-deterministi‐
30       cally.
31

RETURN VALUE

33       No value is returned.
34

ATTRIBUTES

36       For   an   explanation   of   the  terms  used  in  this  section,  see
37       attributes(7).
38
39       ┌──────────┬───────────────┬─────────┐
40Interface Attribute     Value   
41       ├──────────┼───────────────┼─────────┤
42assert()  │ Thread safety │ MT-Safe │
43       └──────────┴───────────────┴─────────┘
44

CONFORMING TO

46       POSIX.1-2001, POSIX.1-2008, C89, C99.  In C89, expression  is  required
47       to  be  of type int and undefined behavior results if it is not, but in
48       C99 it may have any scalar type.
49

BUGS

51       assert() is implemented as a macro; if the expression tested has  side-
52       effects, program behavior will be different depending on whether NDEBUG
53       is defined.  This may create Heisenbugs which go away when debugging is
54       turned on.
55

SEE ALSO

57       abort(3), assert_perror(3), exit(3)
58

COLOPHON

60       This  page  is  part of release 5.02 of the Linux man-pages project.  A
61       description of the project, information about reporting bugs,  and  the
62       latest     version     of     this    page,    can    be    found    at
63       https://www.kernel.org/doc/man-pages/.
64
65
66
67GNU                               2017-09-15                         ASSERT(3)
Impressum