メインコンテンツ

MISRA C:2023 Rule 20.3

The #include directive shall be followed by either a <filename> or "filename" sequence

R2024a 以降

説明

ルール定義

The #include directive shall be followed by either a <filename> or "filename" sequence 1 .

根拠

このルールはマクロの置換後にのみ適用されます。

The behavior is undefined if an #include directive does not use one of the following forms:

  • #include <filename>

  • #include "filename"

Polyspace 実装

#include 命令の後に <file> または "filename" が指定されていない場合、Polyspace® はこのルールの違反を報告します。ここで:

  • <file> は、有効なヘッダー ファイルです。

  • "filename" は、ファイルの名前またはファイルのパスです。

トラブルシューティング

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

すべて展開する

以下の例は、許容される形式に従った、準拠する #include 命令を示しています。#include がマクロ置換後に準拠する形式に従っている場合、Polyspace は、違反を報告しません。


#include"incguard.h"     //Compliant
#include<incguard.h>     //Compliant
#define MH "myheader.h"
#define STR <string>    //Compliant
#include MH             //Compliant
#include STR            //Compliant

この例は、ルールに準拠していない #include 命令を示しています。ヘッダー ファイル名が引用符または角かっこで囲まれていません。


#include myfile.h       //Noncompliant

この例は、ルールに準拠していない #include 命令を示しています。ヘッダー ファイル名を囲んでいるかっこまたは引用符が一致していません。


#include "math.h>       //Noncompliant

チェック情報

グループ: プリプロセッサ命令
カテゴリ: 必要
AGC カテゴリ: 必要

バージョン履歴

R2024a で導入


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.