]>
Commit | Line | Data |
---|---|---|
bf5a7247 | 1 | .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) |
fea681da MK |
2 | .\" |
3 | .\" Permission is granted to make and distribute verbatim copies of this | |
4 | .\" manual provided the copyright notice and this permission notice are | |
5 | .\" preserved on all copies. | |
6 | .\" | |
7 | .\" Permission is granted to copy and distribute modified versions of this | |
8 | .\" manual under the conditions for verbatim copying, provided that the | |
9 | .\" entire resulting derived work is distributed under the terms of a | |
10 | .\" permission notice identical to this one. | |
c13182ef | 11 | .\" |
fea681da MK |
12 | .\" Since the Linux kernel and libraries are constantly changing, this |
13 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
14 | .\" responsibility for errors or omissions, or for damages resulting from | |
15 | .\" the use of the information contained herein. The author(s) may not | |
16 | .\" have taken the same level of care in the production of this manual, | |
17 | .\" which is licensed free of charge, as they might when working | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" License. | |
23 | .\" Modified Sat Jul 24 21:42:42 1993 by Rik Faith <faith@cs.unc.edu> | |
24 | .\" Modified Tue Oct 22 23:44:11 1996 by Eric S. Raymond <esr@thyrsus.com> | |
69962544 | 25 | .TH ASSERT 3 2002-08-25 "GNU" "Linux Programmer's Manual" |
fea681da MK |
26 | .SH NAME |
27 | assert \- abort the program if assertion is false | |
28 | .SH SYNOPSIS | |
29 | .nf | |
30 | .B #include <assert.h> | |
31 | .sp | |
32 | .BI "void assert(scalar " expression ); | |
33 | .fi | |
34 | .SH DESCRIPTION | |
35 | If the macro | |
36 | .B NDEBUG | |
37 | was defined at the moment | |
bd12ab88 | 38 | .I <assert.h> |
fea681da | 39 | was last included, the macro |
63aa9df0 | 40 | .BR assert () |
fea681da MK |
41 | generates no code, and hence does nothing at all. |
42 | Otherwise, the macro | |
63aa9df0 | 43 | .BR assert () |
4c39c55c | 44 | prints an error message to standard error and terminates the program |
fea681da | 45 | by calling |
fb186734 | 46 | .BR abort (3) |
fea681da MK |
47 | if |
48 | .I expression | |
49 | is false (i.e., compares equal to zero). | |
50 | .LP | |
51 | The purpose of this macro is to help the programmer find bugs in | |
c13182ef MK |
52 | his program. |
53 | The message "assertion failed in file foo.c, function | |
fea681da | 54 | do_bar(), line 1287" is of no help at all to a user. |
47297adb | 55 | .SH RETURN VALUE |
fea681da | 56 | No value is returned. |
47297adb | 57 | .SH CONFORMING TO |
68e1685c MK |
58 | POSIX.1-2001, C89, C99. |
59 | In C89, | |
fea681da MK |
60 | .I expression |
61 | is required to be of type | |
9ff08aad | 62 | .I int |
68e1685c | 63 | and undefined behavior results if it is not, but in C99 |
fea681da MK |
64 | it may have any scalar type. |
65 | .\" See Defect Report 107 for more details. | |
66 | .SH BUGS | |
63aa9df0 | 67 | .BR assert () |
fea681da | 68 | is implemented as a macro; if the expression tested has side-effects, |
d9bfdb9c | 69 | program behavior will be different depending on whether |
fea681da | 70 | .B NDEBUG |
c13182ef MK |
71 | is defined. |
72 | This may create Heisenbugs which go away when debugging | |
fea681da | 73 | is turned on. |
47297adb | 74 | .SH SEE ALSO |
fea681da MK |
75 | .BR abort (3), |
76 | .BR assert_perror (3), | |
77 | .BR exit (3) |