]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man3/assert.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / assert.3
index ecd168d429edd42fb2e5344088f9205a1aaf5e38..b5c0e7831ab534a24146dab7e50b0e2575ebbee4 100644 (file)
@@ -1,5 +1,6 @@
-.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
+.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
 .\"
+.\" %%%LICENSE_START(VERBATIM)
 .\" Permission is granted to make and distribute verbatim copies of this
 .\" manual provided the copyright notice and this permission notice are
 .\" preserved on all copies.
 .\"
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
-.\" License.
+.\" %%%LICENSE_END
+.\"
 .\" Modified Sat Jul 24 21:42:42 1993 by Rik Faith <faith@cs.unc.edu>
 .\" Modified Tue Oct 22 23:44:11 1996 by Eric S. Raymond <esr@thyrsus.com>
-.TH ASSERT 3  2002-08-25 "C99" "Linux Programmer's Manual"
+.\" Modified Thu Jun  2 23:44:11 2016 by Nikos Mavrogiannopoulos <nmav@redhat.com>
+.TH ASSERT 3  2017-09-15 "GNU" "Linux Programmer's Manual"
 .SH NAME
 assert \- abort the program if assertion is false
 .SH SYNOPSIS
 .nf
 .B #include <assert.h>
-.sp
+.PP
 .BI "void assert(scalar " expression );
 .fi
 .SH DESCRIPTION
+This macro can help programmers find bugs in their programs,
+or handle exceptional cases
+via a crash that will produce limited debugging output.
+.PP
+If
+.I expression
+is false (i.e., compares equal to zero),
+.BR assert ()
+prints an error message to standard error
+and terminates the program by calling
+.BR abort (3).
+The error message includes the name of the file and function containing the
+.BR assert ()
+call, the source code line number of the call, and the text of the argument;
+something like:
+.PP
+    prog: some_file.c:16: some_func: Assertion `val == 0' failed.
+.PP
 If the macro
 .B NDEBUG
-was defined at the moment
+is defined at the moment
 .I <assert.h>
 was last included, the macro
 .BR assert ()
 generates no code, and hence does nothing at all.
-Otherwise, the macro
+It is not recommended to define
+.B NDEBUG
+if using
 .BR assert ()
-prints an error message to standard error and terminates the program
-by calling
-.BR abort ()
-if
-.I expression
-is false (i.e., compares equal to zero).
-.LP
-The purpose of this macro is to help the programmer find bugs in
-his program.
-The message "assertion failed in file foo.c, function
-do_bar(), line 1287" is of no help at all to a user.
-.SH "RETURN VALUE"
+to detect error conditions since the software
+may behave non-deterministically.
+.SH RETURN VALUE
 No value is returned.
-.SH "CONFORMING TO"
-POSIX.1-2001, C89, C99.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface      Attribute       Value
+T{
+.BR assert ()
+T}     Thread safety   MT-Safe
+.TE
+.sp 1
+.SH CONFORMING TO
+POSIX.1-2001, POSIX.1-2008, C89, C99.
 In C89,
 .I expression
 is required to be of type
@@ -66,12 +93,12 @@ it may have any scalar type.
 .SH BUGS
 .BR assert ()
 is implemented as a macro; if the expression tested has side-effects,
-program behaviour will be different depending on whether
+program behavior will be different depending on whether
 .B NDEBUG
 is defined.
 This may create Heisenbugs which go away when debugging
 is turned on.
-.SH "SEE ALSO"
+.SH SEE ALSO
 .BR abort (3),
 .BR assert_perror (3),
 .BR exit (3)