]> 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 abdf38f92d79ff3e1e688c1ec99f5af3f6533202..b5c0e7831ab534a24146dab7e50b0e2575ebbee4 100644 (file)
 .\"
 .\" 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  2015-03-02 "GNU" "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 (3)
-if
-.I expression
-is false (i.e., compares equal to zero).
-.LP
-The purpose of this macro is to help programmers find bugs in
-their programs.
-The message "assertion failed in file foo.c, function
-do_bar(), line 1287" is of no help at all to a user.
+to detect error conditions since the software
+may behave non-deterministically.
 .SH RETURN VALUE
 No value is returned.
 .SH ATTRIBUTES
@@ -68,7 +80,7 @@ T{
 .BR assert ()
 T}     Thread safety   MT-Safe
 .TE
-
+.sp 1
 .SH CONFORMING TO
 POSIX.1-2001, POSIX.1-2008, C89, C99.
 In C89,