]>
Commit | Line | Data |
---|---|---|
bf5a7247 | 1 | .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) |
fea681da | 2 | .\" |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
a3605969 | 24 | .\" |
fea681da MK |
25 | .\" Modified Sat Jul 24 21:42:42 1993 by Rik Faith <faith@cs.unc.edu> |
26 | .\" Modified Tue Oct 22 23:44:11 1996 by Eric S. Raymond <esr@thyrsus.com> | |
f34fcbb8 | 27 | .\" Modified Thu Jun 2 23:44:11 2016 by Nikos Mavrogiannopoulos <nmav@redhat.com> |
4b8c67d9 | 28 | .TH ASSERT 3 2017-09-15 "GNU" "Linux Programmer's Manual" |
fea681da MK |
29 | .SH NAME |
30 | assert \- abort the program if assertion is false | |
31 | .SH SYNOPSIS | |
32 | .nf | |
33 | .B #include <assert.h> | |
68e4db0a | 34 | .PP |
fea681da MK |
35 | .BI "void assert(scalar " expression ); |
36 | .fi | |
37 | .SH DESCRIPTION | |
4d644289 MK |
38 | This macro can help programmers find bugs in their programs, |
39 | or handle exceptional cases | |
40 | via a crash that will produce limited debugging output. | |
847e0d88 | 41 | .PP |
9b3661c4 | 42 | If |
f34fcbb8 | 43 | .I expression |
9b3661c4 MK |
44 | is false (i.e., compares equal to zero), |
45 | .BR assert () | |
46 | prints an error message to standard error | |
47 | and terminates the program by calling | |
48 | .BR abort (3). | |
49 | The error message includes the name of the file and function containing the | |
50 | .BR assert () | |
51 | call, the source code line number of the call, and the text of the argument; | |
52 | something like: | |
847e0d88 | 53 | .PP |
9b3661c4 | 54 | prog: some_file.c:16: some_func: Assertion `val == 0' failed. |
847e0d88 | 55 | .PP |
fea681da MK |
56 | If the macro |
57 | .B NDEBUG | |
f34fcbb8 | 58 | is defined at the moment |
bd12ab88 | 59 | .I <assert.h> |
fea681da | 60 | was last included, the macro |
63aa9df0 | 61 | .BR assert () |
4d644289 MK |
62 | generates no code, and hence does nothing at all. |
63 | It is not recommended to define | |
f34fcbb8 NM |
64 | .B NDEBUG |
65 | if using | |
63aa9df0 | 66 | .BR assert () |
4d644289 MK |
67 | to detect error conditions since the software |
68 | may behave non-deterministically. | |
47297adb | 69 | .SH RETURN VALUE |
fea681da | 70 | No value is returned. |
d1e3ce2b MS |
71 | .SH ATTRIBUTES |
72 | For an explanation of the terms used in this section, see | |
73 | .BR attributes (7). | |
74 | .TS | |
75 | allbox; | |
76 | lb lb lb | |
77 | l l l. | |
78 | Interface Attribute Value | |
79 | T{ | |
80 | .BR assert () | |
81 | T} Thread safety MT-Safe | |
82 | .TE | |
847e0d88 | 83 | .sp 1 |
47297adb | 84 | .SH CONFORMING TO |
66d463cc | 85 | POSIX.1-2001, POSIX.1-2008, C89, C99. |
68e1685c | 86 | In C89, |
fea681da MK |
87 | .I expression |
88 | is required to be of type | |
9ff08aad | 89 | .I int |
68e1685c | 90 | and undefined behavior results if it is not, but in C99 |
fea681da MK |
91 | it may have any scalar type. |
92 | .\" See Defect Report 107 for more details. | |
93 | .SH BUGS | |
63aa9df0 | 94 | .BR assert () |
fea681da | 95 | is implemented as a macro; if the expression tested has side-effects, |
d9bfdb9c | 96 | program behavior will be different depending on whether |
fea681da | 97 | .B NDEBUG |
c13182ef MK |
98 | is defined. |
99 | This may create Heisenbugs which go away when debugging | |
fea681da | 100 | is turned on. |
47297adb | 101 | .SH SEE ALSO |
fea681da MK |
102 | .BR abort (3), |
103 | .BR assert_perror (3), | |
104 | .BR exit (3) |