]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/assert.3
getauxval.3: Clarify that AT_BASE_PLATFORM and AT_EXECFN return pointers to strings
[thirdparty/man-pages.git] / man3 / assert.3
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 2017-09-15 "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
42 If
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 prog: some_file.c:16: some_func: Assertion `val == 0' failed.
55 .PP
56 If the macro
57 .B NDEBUG
58 is defined at the moment
59 .I <assert.h>
60 was last included, the macro
61 .BR assert ()
62 generates no code, and hence does nothing at all.
63 It is not recommended to define
64 .B NDEBUG
65 if using
66 .BR assert ()
67 to detect error conditions since the software
68 may behave non-deterministically.
69 .SH RETURN VALUE
70 No value is returned.
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
83 .sp 1
84 .SH CONFORMING TO
85 POSIX.1-2001, POSIX.1-2008, C89, C99.
86 In C89,
87 .I expression
88 is required to be of type
89 .I int
90 and undefined behavior results if it is not, but in C99
91 it may have any scalar type.
92 .\" See Defect Report 107 for more details.
93 .SH BUGS
94 .BR assert ()
95 is implemented as a macro; if the expression tested has side-effects,
96 program behavior will be different depending on whether
97 .B NDEBUG
98 is defined.
99 This may create Heisenbugs which go away when debugging
100 is turned on.
101 .SH SEE ALSO
102 .BR abort (3),
103 .BR assert_perror (3),
104 .BR exit (3)