ERR31-C. errno を再定義しない
このガイドラインは廃止され、以下のガイドラインに統合されました。
errno 識別子は、型 int をもつ変更可能な左辺値に展開するが、オブジェクトの識別子である必要はない。それは関数呼び出し(たとえば、*errno())によって得られる変更可能な左辺値に展開してもよい。errno をマクロとするか、外部結合で宣言された識別子とするかは、未規定である。実際のオブジェクトにアクセスするためにマクロ定義を無効にした場合、またはプログラムが名前 errno をもつ識別子を定義した場合、その動作は未定義である(JIS X 3010)。
違反コード
レガシーコードには、次のような誤った宣言が含まれていることが多い。
extern int errno;
適合コード
errno を正しく宣言する方法は、ヘッダ <errno.h> をインクルードすることである。
#include <errno.h>
<errno.h> で errno を宣言することが求められるが、歴史的にはこれを守らない実装も見られる。
リスク評価
errno を再定義することは未定義の動作を引き起こし、誤ったプログラム動作を引き起こす可能性がある。
ルール | 深刻度 | 可能性 | 修正コスト | 優先度 | レベル |
---|---|---|---|---|---|
ERR31-C | 低 | 低 | 低 | P3 | L3 |
自動検出
LDRA ツールスイート V 7.6.0 はこのルールの違反を検出できる。
Compass/ROSE はこのルールの違反を検出できる。
参考情報
- [ISO/IEC 9899:1999] Section 7.5, "Errors <errno.h>"
翻訳元
これは以下のページを翻訳したものです。