メインコンテンツ

MISRA C:2012 Rule 21.1

#define and #undef shall not be used on a reserved identifier or reserved macro name

説明

ルール定義

#define and #undef shall not be used on a reserved identifier or reserved macro name 1 .

根拠

予約された識別子と予約されたマクロ名は実装での使用が想定されています。予約されたマクロの意味を削除または変更すると、未定義の動作が発生する可能性があります。このルールは以下に適用されます。

  • アンダースコアで始まる識別子またはマクロ名

  • C 標準ライブラリに記載されているファイル スコープ内の識別子

  • C 標準ライブラリに記載されているマクロ名で標準ヘッダー内で定義されているもの

ルール チェッカーは、解析で使用されている C 標準のバージョンによって異なる識別子またはマクロにフラグを設定します。C 標準バージョン (-c-version) を参照してください。たとえば、C99 解析を実行する場合は、予約済みの識別子とマクロが ISO®/IEC 9899:1999 標準の第 7 節「Library」で定義されています。

レポート内の追加のメッセージ

  • The macro macro_name shall not be redefined.

  • The macro macro_name shall not be undefined.

  • The macro macro_name shall not be defined.

トラブルシューティング

ルール違反を想定していてもその違反が表示されない場合、コーディング規約違反が想定どおりに表示されない理由の診断を参照します。

すべて展開する

#undef __LINE__               /* Non-compliant - begins with _ */
#define _Guard_H 1            /* Non-compliant - begins with _ */
#undef _BUILTIN_sqrt        /* Non-compliant - implementation may
                               * use _BUILTIN_sqrt for other purposes,
                               * e.g. generating a sqrt instruction */
#define defined               /* Non-compliant - reserved identifier */
#define errno my_errno        /* Non-compliant - library identifier */
#define isneg(x) ( (x) < 0 )  /* Compliant - rule doesn't include  
                               * future library directions   */

チェック情報

グループ: 標準ライブラリ
カテゴリ: 必要
AGC カテゴリ: 必要

バージョン履歴

R2014b で導入


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.