.\" 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. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Modified Sat Jul 24 21:42:42 1993 by Rik Faith .\" Modified Tue Oct 22 23:44:11 1996 by Eric S. Raymond .\" Modified Thu Jun 2 23:44:11 2016 by Nikos Mavrogiannopoulos .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1996 Kentaro OGAWA .\" all rights reserved. .\" Translated Sun, 14 Jul 1996 01:33:26 +0900 .\" by Kentaro OGAWA .\" Updated Fri 6 Oct JST 2000 by Kentaro Shirakata .\" Updated Thu 19 Sep JST 2002 by Kentaro Shirakata .\" .TH ASSERT 3 2017\-09\-15 GNU "Linux Programmer's Manual" .SH 名前 assert \- 診断が偽の時にプログラムを中止する .SH 書式 .nf \fB#include \fP .PP \fBvoid assert(scalar \fP\fIexpression\fP\fB);\fP .fi .SH 説明 このマクロは、プログラマが、プログラムのバグを見つけたり、例外的な場面を (限定的なデバッグ出力を行う) クラッシュで処理するのに役立つ。 .PP \fIexpression\fP が偽 (false) の場合 (つまり \fIexpression\fP が 0 と比較して等しい場合)、 \fBassert\fP() はエラーメッセージを標準エラーに表示し、 \fBabort\fP(3) を呼び出してプログラムを終了する。エラーメッセージには、以下のように、ファイル名、 \fBassert\fP() の呼び出しを含む関数名、呼び出しのソースコードの行番号、引数のテキストが含まれる。 .PP .in +4n .EX prog: some_file.c:16: some_func: Assertion \`val == 0\(aq failed. .EE .in .PP \fI\fP が最後にインクルードされた時点で、 \fBNDEBUG\fP マクロが定義されている場合、 \fBassert\fP() マクロは何のコードも生成せず、したがって全く何もしない。 \fBassert\fP() を使ってエラー条件を検出している場合に \fBNDEBUG\fP を定義するのは推奨されない。ソフトウェアの動作が非決定的になってしまう可能性があるからである。 .SH 返り値 値は返されない。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lb lb lb l l l. インターフェース 属性 値 T{ \fBassert\fP() T} Thread safety MT\-Safe .TE .sp 1 .SH 準拠 .\" See Defect Report 107 for more details. POSIX.1\-2001, POSIX.1\-2008, C89, C99. C89 では \fBexpression\fP は \fIint\fP 型であることが必要とされ、そうでない場合の動作は未定義とされていた。 しかし C99 ではどのようなスカラ値でもよいことになった。 .SH バグ \fBassert\fP() は、マクロとして実装されている。すなわち、評価されている式が副作用を持っている場合には、プログラムの振舞いは、マクロ \fBNDEBUG\fP が定義されているかによって異なるだろう。このため、デバッグを有効にすると消えてしまうハイゼンバグ (Heisenbugs) が起こることがある。 .SH 関連項目 \fBabort\fP(3), \fBassert_perror\fP(3), \fBexit\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。