OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / assert.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
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>
27 .TH ASSERT 3  2013-09-26 "GNU" "Linux Programmer's Manual"
28 .SH NAME
29 assert \- abort the program if assertion is false
30 .SH SYNOPSIS
31 .nf
32 .B #include <assert.h>
33 .sp
34 .BI "void assert(scalar " expression );
35 .fi
36 .SH DESCRIPTION
37 If the macro
38 .B NDEBUG
39 was defined at the moment
40 .I <assert.h>
41 was last included, the macro
42 .BR assert ()
43 generates no code, and hence does nothing at all.
44 Otherwise, the macro
45 .BR assert ()
46 prints an error message to standard error and terminates the program
47 by calling
48 .BR abort (3)
49 if
50 .I expression
51 is false (i.e., compares equal to zero).
52 .LP
53 The purpose of this macro is to help programmers find bugs in
54 their programs.
55 The message "assertion failed in file foo.c, function
56 do_bar(), line 1287" is of no help at all to a user.
57 .SH RETURN VALUE
58 No value is returned.
59 .SH CONFORMING TO
60 POSIX.1-2001, C89, C99.
61 In C89,
62 .I expression
63 is required to be of type
64 .I int
65 and undefined behavior results if it is not, but in C99
66 it may have any scalar type.
67 .\" See Defect Report 107 for more details.
68 .SH BUGS
69 .BR assert ()
70 is implemented as a macro; if the expression tested has side-effects,
71 program behavior will be different depending on whether
72 .B NDEBUG
73 is defined.
74 This may create Heisenbugs which go away when debugging
75 is turned on.
76 .SH SEE ALSO
77 .BR abort (3),
78 .BR assert_perror (3),
79 .BR exit (3)
80 .SH COLOPHON
81 This page is part of release 3.79 of the Linux
82 .I man-pages
83 project.
84 A description of the project,
85 information about reporting bugs,
86 and the latest version of this page,
87 can be found at
88 \%http://www.kernel.org/doc/man\-pages/.