]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/assert.3
namespaces.7: ffix
[thirdparty/man-pages.git] / man3 / assert.3
CommitLineData
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>
3df541c0 28.TH ASSERT 3 2016-07-17 "GNU" "Linux Programmer's Manual"
fea681da
MK
29.SH NAME
30assert \- abort the program if assertion is false
31.SH SYNOPSIS
32.nf
33.B #include <assert.h>
34.sp
35.BI "void assert(scalar " expression );
36.fi
37.SH DESCRIPTION
4d644289
MK
38This macro can help programmers find bugs in their programs,
39or handle exceptional cases
40via a crash that will produce limited debugging output.
9b3661c4
MK
41
42If
f34fcbb8 43.I expression
9b3661c4
MK
44is false (i.e., compares equal to zero),
45.BR assert ()
46prints an error message to standard error
47and terminates the program by calling
48.BR abort (3).
49The error message includes the name of the file and function containing the
50.BR assert ()
51call, the source code line number of the call, and the text of the argument;
52something like:
53
54 prog: some_file.c:16: some_func: Assertion `val == 0' failed.
55
fea681da
MK
56If the macro
57.B NDEBUG
f34fcbb8 58is defined at the moment
bd12ab88 59.I <assert.h>
fea681da 60was last included, the macro
63aa9df0 61.BR assert ()
4d644289
MK
62generates no code, and hence does nothing at all.
63It is not recommended to define
f34fcbb8
NM
64.B NDEBUG
65if using
63aa9df0 66.BR assert ()
4d644289
MK
67to detect error conditions since the software
68may behave non-deterministically.
47297adb 69.SH RETURN VALUE
fea681da 70No value is returned.
d1e3ce2b
MS
71.SH ATTRIBUTES
72For an explanation of the terms used in this section, see
73.BR attributes (7).
74.TS
75allbox;
76lb lb lb
77l l l.
78Interface Attribute Value
79T{
80.BR assert ()
81T} Thread safety MT-Safe
82.TE
83
47297adb 84.SH CONFORMING TO
66d463cc 85POSIX.1-2001, POSIX.1-2008, C89, C99.
68e1685c 86In C89,
fea681da
MK
87.I expression
88is required to be of type
9ff08aad 89.I int
68e1685c 90and undefined behavior results if it is not, but in C99
fea681da
MK
91it may have any scalar type.
92.\" See Defect Report 107 for more details.
93.SH BUGS
63aa9df0 94.BR assert ()
fea681da 95is implemented as a macro; if the expression tested has side-effects,
d9bfdb9c 96program behavior will be different depending on whether
fea681da 97.B NDEBUG
c13182ef
MK
98is defined.
99This may create Heisenbugs which go away when debugging
fea681da 100is turned on.
47297adb 101.SH SEE ALSO
fea681da
MK
102.BR abort (3),
103.BR assert_perror (3),
104.BR exit (3)