]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man/man3/assert.3
man/, share/mk/: Move man*/ to man/
[thirdparty/man-pages.git] / man / man3 / assert.3
CommitLineData
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
11assert \- abort the program if assertion is false
b813014f
AC
12.SH LIBRARY
13Standard 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
22This macro can help programmers find bugs in their programs,
23or handle exceptional cases
24via a crash that will produce limited debugging output.
c6d039a3 25.P
9b3661c4 26If
f34fcbb8 27.I expression
9b3661c4
MK
28is false (i.e., compares equal to zero),
29.BR assert ()
30prints an error message to standard error
31and terminates the program by calling
32.BR abort (3).
33The error message includes the name of the file and function containing the
34.BR assert ()
35call, the source code line number of the call, and the text of the argument;
36something like:
c6d039a3 37.P
be266c07
MK
38.in +4n
39.EX
b957f81f 40prog: some_file.c:16: some_func: Assertion \`val == 0\[aq] failed.
be266c07
MK
41.EE
42.in
c6d039a3 43.P
fea681da
MK
44If the macro
45.B NDEBUG
f34fcbb8 46is defined at the moment
bd12ab88 47.I <assert.h>
fea681da 48was last included, the macro
63aa9df0 49.BR assert ()
4d644289
MK
50generates no code, and hence does nothing at all.
51It is not recommended to define
f34fcbb8
NM
52.B NDEBUG
53if using
63aa9df0 54.BR assert ()
4d644289
MK
55to detect error conditions since the software
56may behave non-deterministically.
47297adb 57.SH RETURN VALUE
fea681da 58No value is returned.
d1e3ce2b
MS
59.SH ATTRIBUTES
60For an explanation of the terms used in this section, see
61.BR attributes (7).
62.TS
63allbox;
c466875e 64lbx lb lb
d1e3ce2b
MS
65l l l.
66Interface Attribute Value
67T{
9e54434e
BR
68.na
69.nh
d1e3ce2b
MS
70.BR assert ()
71T} Thread safety MT-Safe
72.TE
3113c7f3 73.SH STANDARDS
4131356c
AC
74C11, POSIX.1-2008.
75.SH HISTORY
76C89, C99, POSIX.1-2001.
c6d039a3 77.P
e0089d55
AC
78In C89,
79.I expression
80is required to be of type
81.I int
82and undefined behavior results if it is not, but in C99
83it may have any scalar type.
84.\" See Defect Report 107 for more details.
fea681da 85.SH BUGS
63aa9df0 86.BR assert ()
fea681da 87is implemented as a macro; if the expression tested has side-effects,
d9bfdb9c 88program behavior will be different depending on whether
fea681da 89.B NDEBUG
c13182ef
MK
90is defined.
91This may create Heisenbugs which go away when debugging
fea681da 92is turned on.
47297adb 93.SH SEE ALSO
fea681da
MK
94.BR abort (3),
95.BR assert_perror (3),
96.BR exit (3)