assert.3: Improved description

Removed text referring to text not being helpful to users. Provide
the error text instead to allow the reader to determine whether it
is helpful.  Recommend against using NDEBUG for programs to
exhibit deterministic behavior.  Moved description ahead of
recommendations.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
This commit is contained in:
Nikos Mavrogiannopoulos 2016-06-03 07:08:50 +02:00 committed by Michael Kerrisk
parent 69a7267960
commit f34fcbb86b
1 changed files with 16 additions and 15 deletions

View File

@ -24,6 +24,7 @@
.\"
.\" 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>
.\" Modified Thu Jun 2 23:44:11 2016 by Nikos Mavrogiannopoulos <nmav@redhat.com>
.TH ASSERT 3 2015-08-08 "GNU" "Linux Programmer's Manual"
.SH NAME
assert \- abort the program if assertion is false
@ -34,26 +35,26 @@ assert \- abort the program if assertion is false
.BI "void assert(scalar " expression );
.fi
.SH DESCRIPTION
If the macro
.B NDEBUG
was 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
.BR assert ()
prints an error message to standard error and terminates the program
by calling
This macro can help programmers find bugs in their programs, or handle exceptional cases
via a crash that will produce limited debugging output. The function will print an
error message to standard error, e.g., "assertion failed in file foo.c, function do_bar(), line 1287"
and terminate 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.
If the macro
.B NDEBUG
is defined at the moment
.I <assert.h>
was last included, the macro
.BR assert ()
generates no code, and hence does nothing at all. It is not recommended to define
.B NDEBUG
if using
.BR assert ()
to detect error conditions since the software may behave non-deterministically.
.SH RETURN VALUE
No value is returned.
.SH ATTRIBUTES