assert_perrorのヘルプ・マニュアル
日本語 英語
assert_perror --help
man assert_perror
ASSERT_PERROR(3) Linux Programmer’s Manual ASSERT_PERROR(3)
名前
assert_perror - test errnum and abort
書式
#define _GNU_SOURCE
#include
void assert_perror(int errnum);
説明
最 後に がインクルードされた時にマクロ NDEBUG が定義されてい
た場合、マクロ assert_perror() は何のコードも生成せず、したがって全く何
もしない。そうでない場合、マクロ assert_perror() は標準エラーにエラー・
メッセージを表示し、 errnum が 0 でない場合には abort(3) を呼び出してプ
ロ グラムを終了させる。メッセージには、ファイル名、マクロ呼び出しがあっ
た関数名と行番号、 strerror(errnum) の出力が含まれる。
返り値
返り値はない。
準拠
これは GNU による拡張である。
バグ
assert マクロの目的は、プログラマがプログラム中のバグを探す手助けをする
こ とであり、コーディング間違いがない場合には何が起こることはありえない
。しかしながら、システムコールやライブラリコールの場合、状況がかなり 違
っ ていて、エラーが返されることがありえるし、実際あるだろう。そしてその
ような状況でもテストされるべきである。この場合には、 NDEBUG を定義す る
こ とで無効にできる assert ではなく、適切なエラー処理コードで対処すべき
である。このマクロは決して使わないこと。
関連項目
abort(3), assert(3), exit(3), strerror(3), feature_test_macros(7)
GNU 2002-08-25 ASSERT_PERROR(3)
ASSERT_PERROR(3) Linux Programmer’s Manual ASSERT_PERROR(3)
NAME
assert_perror - test errnum and abort
SYNOPSIS
#define _GNU_SOURCE
#include
void assert_perror(int errnum);
DESCRIPTION
If the macro NDEBUG was defined at the moment was last
included, the macro assert_perror() generates no code, and hence does
nothing at all. Otherwise, the macro assert_perror() prints an error
message to standard error and terminates the program by calling
abort(3) if errnum is non-zero. The message contains the filename,
function name and line number of the macro call, and the output of str-
error(errnum).
RETURN VALUE
No value is returned.
CONFORMING TO
This is a GNU extension.
BUGS
The purpose of the assert macros is to help the programmer find bugs in
his program, things that cannot happen unless there was a coding mis-
take. However, with system or library calls the situation is rather
different, and error returns can happen, and will happen, and should be
tested for. Not by an assert, where the test goes away when NDEBUG is
defined, but by proper error handling code. Never use this macro.
SEE ALSO
abort(3), assert(3), exit(3), strerror(3), feature_test_macros(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2002-08-25 ASSERT_PERROR(3)