MISRA C:2012 Rule 20.1
#include directives should only be preceded by preprocessor directives or comments
説明
ルール定義
#include directives should only be preceded by preprocessor directives or comments 1 .
根拠
コードの可読性向上のために、ソース ファイルの先頭でファイル内のすべての #include 命令をグループ化します。#include を使用して標準ヘッダー ファイルを宣言または定義内にインクルードする場合、あるいは関連する標準ヘッダー ファイルをインクルードする前に標準ライブラリの一部を使用する場合に、未定義の動作が発生します。
Polyspace 実装
Polyspace® は #include 命令の前にあるテキストにフラグを設定します。Polyspace はプリプロセッサ命令、コメント、スペースまたは改行文字を無視します。Polyspace は、#if または #ifdef などの条件付きコンパイル命令を使用して非表示にされるコードも無視します。
トラブルシューティング
ルール違反を想定していてもその違反が表示されない場合、コーディング規約違反が想定どおりに表示されない理由の診断を参照します。
例
チェック情報
| グループ: プリプロセッサ命令 |
| カテゴリ: 推奨 |
| AGC カテゴリ: 推奨 |
バージョン履歴
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.