malloc.3: ffix
[man-pages.git] / man3 / assert.3
bloba54d5f5e2d010ebf2da6ad85f9b7b0b2c1b533cf
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
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>
27 .\" Modified Thu Jun  2 23:44:11 2016 by Nikos Mavrogiannopoulos <nmav@redhat.com>
28 .TH ASSERT 3  2021-03-22 "GNU" "Linux Programmer's Manual"
29 .SH NAME
30 assert \- abort the program if assertion is false
31 .SH SYNOPSIS
32 .nf
33 .B #include <assert.h>
34 .PP
35 .BI "void assert(scalar " expression );
36 .fi
37 .SH DESCRIPTION
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.
41 .PP
43 .I expression
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:
53 .PP
54 .in +4n
55 .EX
56 prog: some_file.c:16: some_func: Assertion \`val == 0\(aq failed.
57 .EE
58 .in
59 .PP
60 If the macro
61 .B NDEBUG
62 is defined at the moment
63 .I <assert.h>
64 was last included, the macro
65 .BR assert ()
66 generates no code, and hence does nothing at all.
67 It is not recommended to define
68 .B NDEBUG
69 if using
70 .BR assert ()
71 to detect error conditions since the software
72 may behave non-deterministically.
73 .SH RETURN VALUE
74 No value is returned.
75 .SH ATTRIBUTES
76 For an explanation of the terms used in this section, see
77 .BR attributes (7).
78 .ad l
79 .nh
80 .TS
81 allbox;
82 lbx lb lb
83 l l l.
84 Interface       Attribute       Value
86 .BR assert ()
87 T}      Thread safety   MT-Safe
88 .TE
89 .hy
90 .ad
91 .sp 1
92 .SH CONFORMING TO
93 POSIX.1-2001, POSIX.1-2008, C89, C99.
94 In C89,
95 .I expression
96 is required to be of type
97 .I int
98 and undefined behavior results if it is not, but in C99
99 it may have any scalar type.
100 .\" See Defect Report 107 for more details.
101 .SH BUGS
102 .BR assert ()
103 is implemented as a macro; if the expression tested has side-effects,
104 program behavior will be different depending on whether
105 .B NDEBUG
106 is defined.
107 This may create Heisenbugs which go away when debugging
108 is turned on.
109 .SH SEE ALSO
110 .BR abort (3),
111 .BR assert_perror (3),
112 .BR exit (3)