]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
bf5a7247 | 2 | .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) |
fea681da | 3 | .\" |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
a3605969 | 5 | .\" |
fea681da MK |
6 | .\" Modified Sat Jul 24 21:42:42 1993 by Rik Faith <faith@cs.unc.edu> |
7 | .\" Modified Tue Oct 22 23:44:11 1996 by Eric S. Raymond <esr@thyrsus.com> | |
f34fcbb8 | 8 | .\" Modified Thu Jun 2 23:44:11 2016 by Nikos Mavrogiannopoulos <nmav@redhat.com> |
4c1c5274 | 9 | .TH assert 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
10 | .SH NAME |
11 | assert \- abort the program if assertion is false | |
b813014f AC |
12 | .SH LIBRARY |
13 | Standard C library | |
14 | .RI ( libc ", " \-lc ) | |
fea681da MK |
15 | .SH SYNOPSIS |
16 | .nf | |
17 | .B #include <assert.h> | |
c6d039a3 | 18 | .P |
fea681da MK |
19 | .BI "void assert(scalar " expression ); |
20 | .fi | |
21 | .SH DESCRIPTION | |
4d644289 MK |
22 | This macro can help programmers find bugs in their programs, |
23 | or handle exceptional cases | |
24 | via a crash that will produce limited debugging output. | |
c6d039a3 | 25 | .P |
9b3661c4 | 26 | If |
f34fcbb8 | 27 | .I expression |
9b3661c4 MK |
28 | is false (i.e., compares equal to zero), |
29 | .BR assert () | |
30 | prints an error message to standard error | |
31 | and terminates the program by calling | |
32 | .BR abort (3). | |
33 | The error message includes the name of the file and function containing the | |
34 | .BR assert () | |
35 | call, the source code line number of the call, and the text of the argument; | |
36 | something like: | |
c6d039a3 | 37 | .P |
be266c07 MK |
38 | .in +4n |
39 | .EX | |
b957f81f | 40 | prog: some_file.c:16: some_func: Assertion \`val == 0\[aq] failed. |
be266c07 MK |
41 | .EE |
42 | .in | |
c6d039a3 | 43 | .P |
fea681da MK |
44 | If the macro |
45 | .B NDEBUG | |
f34fcbb8 | 46 | is defined at the moment |
bd12ab88 | 47 | .I <assert.h> |
fea681da | 48 | was last included, the macro |
63aa9df0 | 49 | .BR assert () |
4d644289 MK |
50 | generates no code, and hence does nothing at all. |
51 | It is not recommended to define | |
f34fcbb8 NM |
52 | .B NDEBUG |
53 | if using | |
63aa9df0 | 54 | .BR assert () |
4d644289 MK |
55 | to detect error conditions since the software |
56 | may behave non-deterministically. | |
47297adb | 57 | .SH RETURN VALUE |
fea681da | 58 | No value is returned. |
d1e3ce2b MS |
59 | .SH ATTRIBUTES |
60 | For an explanation of the terms used in this section, see | |
61 | .BR attributes (7). | |
62 | .TS | |
63 | allbox; | |
c466875e | 64 | lbx lb lb |
d1e3ce2b MS |
65 | l l l. |
66 | Interface Attribute Value | |
67 | T{ | |
9e54434e BR |
68 | .na |
69 | .nh | |
d1e3ce2b MS |
70 | .BR assert () |
71 | T} Thread safety MT-Safe | |
72 | .TE | |
3113c7f3 | 73 | .SH STANDARDS |
4131356c AC |
74 | C11, POSIX.1-2008. |
75 | .SH HISTORY | |
76 | C89, C99, POSIX.1-2001. | |
c6d039a3 | 77 | .P |
e0089d55 AC |
78 | In C89, |
79 | .I expression | |
80 | is required to be of type | |
81 | .I int | |
82 | and undefined behavior results if it is not, but in C99 | |
83 | it may have any scalar type. | |
84 | .\" See Defect Report 107 for more details. | |
fea681da | 85 | .SH BUGS |
63aa9df0 | 86 | .BR assert () |
fea681da | 87 | is implemented as a macro; if the expression tested has side-effects, |
d9bfdb9c | 88 | program behavior will be different depending on whether |
fea681da | 89 | .B NDEBUG |
c13182ef MK |
90 | is defined. |
91 | This may create Heisenbugs which go away when debugging | |
fea681da | 92 | is turned on. |
47297adb | 93 | .SH SEE ALSO |
fea681da MK |
94 | .BR abort (3), |
95 | .BR assert_perror (3), | |
96 | .BR exit (3) |