OSDN Git Service

e46cf9c897968ba487cf5a6d120d722164354cb9
[linuxjm/LDP_man-pages.git] / draft / man3 / assert.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\" License.
23 .\" Modified Sat Jul 24 21:42:42 1993 by Rik Faith <faith@cs.unc.edu>
24 .\" Modified Tue Oct 22 23:44:11 1996 by Eric S. Raymond <esr@thyrsus.com>
25 .\"
26 .\" Japanese Version Copyright (c) 1996 Kentaro OGAWA
27 .\"         all rights reserved.
28 .\" Translated Sun, 14 Jul 1996 01:33:26 +0900
29 .\"         by Kentaro OGAWA <k_ogawa@oyna.cc.muroran-it.ac.jp>
30 .\" Updated Fri  6 Oct JST 2000 by Kentaro Shirakata <argrath@ub32.org>
31 .\" Updated Thu 19 Sep JST 2002 by Kentaro Shirakata <argrath@ub32.org>
32 .\"
33 .TH ASSERT 3  2002-08-25 "GNU" "Linux Programmer's Manual"
34 .SH 名前
35 assert \- 診断が偽の時にプログラムを中止する
36 .SH 書式
37 .nf
38 .B #include <assert.h>
39 .sp
40 .BI "void assert(scalar " expression );
41 .fi
42 .SH 説明
43 .\"O If the macro
44 .\"O .B NDEBUG
45 .\"O was defined at the moment
46 .\"O .I <assert.h>
47 .\"O was last included, the macro
48 .\"O .BR assert ()
49 .\"O generates no code, and hence does nothing at all.
50 .I <assert.h>
51 が最後にインクルードされた時点で、
52 .B NDEBUG
53 マクロが定義されていた場合、
54 .BR assert ()
55 マクロは何のコードも生成せず、従って全く何もしない。
56 .\"O Otherwise, the macro
57 .\"O .BR assert ()
58 .\"O prints an error message to standard error and terminates the program
59 .\"O by calling
60 .\"O .BR abort (3)
61 .\"O if
62 .\"O .I expression
63 .\"O is false (i.e., compares equal to zero).
64 さもなければ、
65 .BR assert (3)
66 マクロは
67 .I expression
68 が偽の時(すなわち、比較の結果が0と等しい時)に
69 標準エラー出力にエラーメッセージを表示し、さらに
70 .BR abort ()
71 を呼び出すことによって、プログラムを終了させる。
72 .LP
73 .\"O The purpose of this macro is to help the programmer find bugs in
74 .\"O his program.
75 .\"O The message "assertion failed in file foo.c, function
76 .\"O do_bar(), line 1287" is of no help at all to a user.
77 このマクロの目的は、プログラマーがプログラムのバグを発見する手助けを
78 することである。"assertion failed in file foo.c, function do_bar(), line 1287"
79 というメッセージはユーザーには何の助けにもならない。
80 .SH 返り値
81 値は返されない。
82 .SH 準拠
83 .\"O POSIX.1-2001, C89, C99.
84 .\"O In C89,
85 .\"O .B expression
86 .\"O is required to be of type
87 .\"O .I int
88 .\"O and undefined behavior results if it is not, but in C99
89 .\"O it may have any scalar type.
90 POSIX.1-2001, C89, C99.
91 C89 では
92 .B expression
93
94 .I int
95 型であることが必要とされ、そうでない場合の動作は未定義とされていた。
96 しかし C99 ではどのようなスカラ値でもよいことになった。
97 .\"O .\" See Defect Report 107 for more details.
98 .\" 詳細は不具合報告 107 を参照のこと。
99 .SH バグ
100 .\"O .BR assert ()
101 .\"O is implemented as a macro; if the expression tested has side-effects,
102 .\"O program behavior will be different depending on whether
103 .\"O .B NDEBUG
104 .\"O is defined.
105 .\"O This may create Heisenbugs which go away when debugging
106 .\"O is turned on.
107 .BR assert ()
108 は、マクロとして実装されている。すなわち、
109 試されている式が副作用を持っている場合には、
110 マクロ
111 .B NDEBUG
112 が定義されているかどうかに依存して、プログラムの振舞いは異なるだろう。
113 これによって、バグ出しするときには消えてしまう
114 ハイゼンバグ(Heisenbugs)を生み出すだろう。
115 .SH 関連項目
116 .BR abort (3),
117 .BR assert_perror (3),
118 .BR exit (3)