1assert(3)                  Library Functions Manual                  assert(3)
2
3
4

NAME

6       assert - abort the program if assertion is false
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <assert.h>
13
14       void assert(scalar expression);
15

DESCRIPTION

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

RETURN VALUE

36       No value is returned.
37

ATTRIBUTES

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

STANDARDS

49       C11, POSIX.1-2008.
50

HISTORY

52       C89, C99, POSIX.1-2001.
53
54       In C89, expression is required to be of type int and undefined behavior
55       results if it is not, but in C99 it may have any scalar type.
56

BUGS

58       assert()  is implemented as a macro; if the expression tested has side-
59       effects, program behavior will be different depending on whether NDEBUG
60       is defined.  This may create Heisenbugs which go away when debugging is
61       turned on.
62

SEE ALSO

64       abort(3), assert_perror(3), exit(3)
65
66
67
68Linux man-pages 6.04              2023-03-30                         assert(3)
Impressum