メインコンテンツ

MISRA C:2004 および MISRA AC AGC コーディング ルール

メモ

将来のリリースでは、Bug Finder で MISRA C™:2004 および MISRA™ AC AGC コーディング ルールへの準拠のチェックがサポートされなくなる予定です。これらの規約の代わりに、MISRA C:2023 規約を使用します。MISRA C:2023 のチェック (-misra-c-2023) を参照してください。生成されたコードを解析する際は、MISRA C:2023 を使用し、オプション [生成されたコードの要件を使用] (-misra-c-2023-agc-mode) を指定します。

サポートされている MISRA C:2004 および MISRA AC AGC ルール

次の表に、Polyspace™ コーディング ルール チェッカーでサポートされている MISRA C:2004 コーディング ルールを示します。各ルールのチェック方法およびチェック範囲の制限の詳細は、「Polyspace 仕様」列に記載されています。

メモ

Polyspace コーディング ルール チェッカーについて、次の点に注意してください。

  • ルール 4.1、5.1、5.3、6.1、6.3、7.1、9.2、10.5、12.6、13.5 および 15.0 については、MISRA-C:2004 Technical Corrigendum 1 をサポートしています。

  • MISRA AC AGC Guidelines for the Application of MISRA-C:2004 in the Context of Automatic Code Generation」で規定されているルールをチェックします。

このソフトウェアでは、解析のコンパイル段階で違反の大部分が報告されます。ただし、ルール 9.1 (Non-initialized variable)、12.11 (-scalar-overflows-checks signed-and-unsigned を使用したオーバーフロー チェックの一種)、13.7 (デッド コード)、14.1 (デッド コード)、16.2 および 21.1 の違反は、コード解析時に検出され、ランタイム エラーとして報告されます。

メモ

ルール 13.7 および 14.1 の違反の一部は、解析のコンパイル段階で報告されます。

トラブルシューティング

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

サポートされているコーディング ルールのリスト

環境

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
1.1All code shall conform to ISO® 9899:1990 "Programming languages - C", amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996.

All code shall conform to ISO 9899:1990 Programming languages C, amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996 というテキストの後に次のメッセージがそれぞれ表示されます。

  • ANSI® C does not allow ‘#include_next'

  • ANSI C does not allow macros with variable arguments list

  • ANSI C does not allow ‘#assert’

  • ANSI C does not allow '#unassert'

  • ANSI C does not allow testing assertions

  • ANSI C does not allow '#ident'

  • ANSI C does not allow '#sccs'

  • text following '#else' violates ANSI standard.

  • text following '#endif' violates ANSI standard.

  • text following '#else' or '#endif' violates ANSI standard.

  • ANSI C90 forbids 'long long int' type.

  • ANSI C90 forbids 'long double' type.

  • ANSI C90 forbids long long integer constants.

  • Keyword 'inline' should not be used.

  • Array of zero size should not be used.

  • Integer constant does not fit within unsigned long int.

  • Integer constant does not fit within long int.

  • Too many nesting levels of #includes: N1. The limit is N0.

  • Too many macro definitions: N1. The limit is N0.

  • Too many nesting levels for control flow: N1. The limit is N0.

  • Too many enumeration constants: N1. The limit is N0.

サポートされているすべての拡張機能は、この MISRA ルールの違反となります。標準のコンパイル エラー メッセージはこの MISRA ルールの違反にはならず、変更されません。

言語の拡張

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
2.1Assembly language shall be encapsulated and isolated.Assembly language shall be encapsulated and isolated.

コードが以下でカプセル化されている場合、警告は出力されません。

  • 関数 asm または asm pragma

  • マクロ

2.2Source code shall only use /* */ style commentsC++ comments shall not be used.

C++ コメントはコメントとして処理されますが、この MISRA ルールの違反となります。

メモ: このルールについては、ソース コードに注釈を付けることができません。

2.3The character sequence /* shall not be used within a commentThe character sequence /* shall not appear within a comment.

このルール違反は C++ コメント内に文字列 /* がある場合も発生します。

メモ: このルールについては、ソース コードに注釈を付けることができません。

2.4Sections of code should not be "commented out"Sections of code should not be "commented out"

チェッカーは内部でヒューリスティックな方法を使用してコメントアウトされたコードを検出します。たとえば、#;{} などの文字はコードを含む可能性があるコメントを示します。このようなコメントは他のメトリクスに対して評価されて、コメントになりすましたコードである可能性を判断します。たとえば、数個の単語が間に記号をはさまずに連続していれば、この可能性は減少します。

チェッカーは、コードを含んでいても次のコメントに対してはフラグを設定しません。

  • /** または /*! で始まる doxygen コメント。

  • 同じ記号を複数個繰り返すコメント。たとえば、次の場合の = 記号。

    /* =====================================
     * A comment
     * =====================================*/

  • ファイルの最初の行のコメント。

  • C スタイル (/* */) と C++ スタイル (//) が混在したコメント。

チェッカーは、このようなコメントがドキュメンテーション目的か、または事前に考慮されたうえで意図的に入力されたものと見なします。

ドキュメンテーション

ルールMISRA 定義レポート ファイル メッセージPolyspace 実装
3.4

All uses of the #pragma directive shall be documented and explained.

All uses of the #pragma directive shall be documented and explained.このルールをチェックするには、オプション許可されるプラグマ (-allowed-pragmas)を使用してソース ファイルで許可されるプラグマをリストしなければなりません。Polyspace によって、許可されるプラグマ リストにないプラグマが検出された場合、違反になります。

文字セット

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
4.1Only those escape sequences which are defined in the ISO C standard shall be used.\<character> is not an ISO C escape sequence Only those escape sequences which are defined in the ISO C standard shall be used. 
4.2Trigraphs shall not be used.Trigraphs shall not be used.3 文字表記は処理され、等価な文字に変換されますが、MISRA ルールの違反となります。

識別子

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
5.1Identifiers (internal and external) shall not rely on the significance of more than 31 charactersIdentifier 'XX' should not rely on the significance of more than 31 characters.

すべての識別子 (グローバル、静的およびローカル) がチェックされます。

レビューを容易にするため、ルール チェッカーは、先頭の 31 文字が同じ識別子をすべて 1 つのルール違反として示します。ルール違反のイベント履歴内で識別子の名前が競合するすべてのインスタンスを確認できます。

このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされますPolyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください

5.2

Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier.

  • Local declaration of XX is hiding another identifier.

  • Declaration of parameter XX is hiding another identifier.

ルール 8.1 に違反していないことを前提としています。

5.3

A typedef name shall be a unique identifier

{typedef name}'%s' should not be reused. (already used as {typedef name} at %s:%d)

typedef 名が別の識別子名として再利用されている場合、警告されます。

5.4

A tag name shall be a unique identifier

{tag name}'%s' should not be reused. (already used as {tag name} at %s:%d)

タグ名が別の識別子名として再利用されている場合、警告されます。

このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされますPolyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください

5.5

No object or function identifier with a static storage duration should be reused.

{static identifier/parameter name}’%s’ should not be reused. (already used as {static identifier/parameter name} with static storage duration at %s:%d)

静的な名前が別の識別子名として再利用されている場合、警告されます。

5.6

No identifier in one name space should have the same spelling as an identifier in another name space, with the exception of structure and union member names.

{member name}'%s' should not be reused. (already used as {member name} at %s:%d)

ある名前空間の idf が別の名前空間で再利用されている場合、警告されます。

このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされますPolyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください

5.7

No identifier name should be reused.

{identifier}'%s' should not be reused. (already used as {identifier} at %s:%d)

次の場合、違反は報告されません。

  • 異なる関数で、同じ名前のパラメーターを使用している

  • 異なる関数で、同じ名前のローカル変数を使用している

  • ある関数で、別の関数のパラメーターと同じ名前のローカル変数を使用している

番号MISRA 定義レポート ファイル メッセージPolyspace 実装

6.1

The plain char type shall be used only for the storage and use of character values

Only permissible operators on plain chars are '=', '==' or '!=' operators, explicit casts to integral types and '?' (for the 2nd and 3rd operands)

プレーンの char 型が、=、==、!= 以外の演算子と共に使用されている、整数型への明示的なキャストで使用されている、あるいは ? 演算子の第 2 オペランドまたは第 3 オペランドとして使用されている場合、警告されます。

6.2

Signed and unsigned char type shall be used only for the storage and use of numeric values.
  • Value of type plain char is implicitly converted to signed char.

  • Value of type plain char is implicitly converted to unsigned char.

  • Value of type signed char is implicitly converted to plain char.

  • Value of type unsigned char is implicitly converted to plain char.

プレーンの char 型の値が符号付き char 型または符号なし char 型に暗黙的に変換されている場合、警告されます。

6.3

typedefs that indicate size and signedness should be used in place of the basic types

typedefs that indicate size and signedness should be used in place of the basic types.

typedef の定義では、警告は出力されません。

6.4

Bit fields shall only be defined to be of type unsigned int or signed int.

Bit fields shall only be defined to be of type unsigned int or signed int.

 

6.5

Bit fields of type signed int shall be at least 2 bits long.

Bit fields of type signed int shall be at least 2 bits long.

幅が 0 である無名の符号付き int 型ビット フィールドに対しては警告はありません。サイズが 1 以下であるすべての符号付きビット フィールドに適用されます (ルール 6.4 に違反している場合)。

定数

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
7.1Octal constants (other than zero) and octal escape sequences shall not be used.
  • Octal constants other than zero and octal escape sequences shall not be used.

  • Octal constants (other than zero) should not be used.

  • Octal escape sequences should not be used.

 

宣言と定義

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
8.1

Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call.

  • Function XX has no complete prototype visible at call.

  • Function XX has no prototype visible at definition.

呼び出しで参照可能なプロトタイプは完全でなければなりません。

8.2

Whenever an object or function is declared or defined, its type shall be explicitly stated

Whenever an object or function is declared or defined, its type shall be explicitly stated.

 
8.3For each function parameter the type given in the declaration and definition shall be identical, and the return types shall also be identical.Definition of function 'XX' incompatible with its declaration.ルール 8.1 に違反していないことを前提としています。このルールは互換性のある型に限定されます。オフにできます。
8.4

If objects or functions are declared more than once their types shall be compatible.

  • If objects or functions are declared more than once their types shall be compatible.

  • Global declaration of 'XX' function has incompatible type with its definition.

  • Global declaration of 'XX' variable has incompatible type with its definition.

このルールの違反はリンク段階で生成されることがあります。

このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされますPolyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください

8.5

There shall be no definitions of objects or functions in a header file

  • Object 'XX' should not be defined in a header file.

  • Function 'XX' should not be defined in a header file.

  • Fragment of function should not be defined in a header file.

仮定義は定義と見なされます。ファイル スコープのオブジェクトの場合、仮定義は次のような宣言となります。

  • 初期化子をもたない。

  • ストレージ クラス指定子をもたないか static 指定子をもつ

8.6

Functions shall always be declared at file scope.

Function 'XX' should be declared at file scope.

このルールは ISO/IEC TS 17961 ID addrescape に対応しています。

8.7Objects shall be defined at block scope if they are only accessed from within a single functionObject 'XX' should be declared at block scope.静的オブジェクトに限定されます。
8.8An external object or function shall be declared in one file and only one fileFunction/Object 'XX' has external declarations in multiple files.

明示的な外部宣言に制限されます (仮定義は無視されます)。

Polyspace では、ヘッダー ファイル以外で extern と宣言された変数または関数をこのルールに違反するものと見なします。

8.9

An identifier with external linkage shall have exactly one external definition.

  • Procedure/Global variable XX multiply defined.

  • Forbidden multiple tentative definitions for object XX

  • Global variable has multiple tentative definitions

  • Undefined global variable XX

チェッカーでは、定義が異なるファイルに出現している場合にのみ、複数の定義にフラグを設定します。

事前定義されたシンボルへの警告はありません。

このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされますPolyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください

8.10

All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required

Function/Variable XX should have internal linkage.

ルール 8.1 に違反していないことを前提としています。0 が使用されている場合、警告はありません。

コードに main 関数が含まれておらず、値 custom と一緒に [初期化する変数] (-main-generator-writes-variables) などのオプションを使用して、初期化する変数のセットを明示的に指定した場合は、チェッカーがそれらの変数にフラグを設定しません。チェッカーは、実際のアプリケーションでは、現在変数を使用しているファイルに加えて、main を含むファイルでも変数を初期化する必要があると見なします。そのため、変数は複数の翻訳単位内で使用されなければなりません。

このチェッカーは、既定の Polyspace as You Code 解析では非アクティブにされますPolyspace as You Code 解析で非アクティブにされるチェッカー (Polyspace Access)を参照してください

8.11

The static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkage

static storage class specifier should be used on internal linkage symbol XX.

 
8.12

When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization

Size of array 'XX' should be explicitly stated.

 

初期化

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
9.1

All automatic variables shall have been assigned a value before being used.

 

Polyspace は、コードに以下の問題が含まれている場合にこの違反を報告します。

9.2

Braces shall be used to indicate and match the structure in the nonzero initialisation of arrays and structures.

Braces shall be used to indicate and match the structure in the nonzero initialization of arrays and structures.

 
9.3

In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.

In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.

 

演算型変換

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
10.1

The value of an expression of integer type shall not be implicitly converted to a different underlying type if:

  • it is not a conversion to a wider integer type of the same signedness, or

  • the expression is complex, or

  • the expression is not constant and is a function argument, or

  • the expression is not constant and is a return expression

  • Implicit conversion of the expression of underlying type XX to the type XX that is not a wider integer type of the same signedness.

  • Implicit conversion of one of the binary operands whose underlying types are XX and XX

  • Implicit conversion of the binary right hand operand of underlying type XX to XX that is not an integer type.

  • Implicit conversion of the binary left hand operand of underlying type XX to XX that is not an integer type.

  • Implicit conversion of the binary right hand operand of underlying type XX to XX that is not a wider integer type of the same signedness or Implicit conversion of the binary ? left hand operand of underlying type XX to XX, but it is a complex expression.

  • Implicit conversion of complex integer expression of underlying type XX to XX.

  • Implicit conversion of non-constant integer expression of underlying type XX in function return whose expected type is XX.

  • Implicit conversion of non-constant integer expression of underlying type XX as argument of function whose corresponding parameter type is XX.

ANSI C 基本データ型の順序 (符号付きの char、short、int、long) は、T2 が T1 の右側にある場合は T2 が T1 よりも大きいか、T2 = T1 であることを意味します。符号なしの基本データ型にも同じ解釈が適用されます。

bool 型または enum 型の式は、int 型を潜在型としてもちます。

プレーンの char 型は、符号付きの基となる型をもつことも、符号なしの潜在型をもつこともあります (Polyspace のターゲット構成またはオプション設定に依存)。

struct.bitfield の単純な式の潜在型はビット フィールドの定義で使用される基本データ型です。ビット フィールドの幅は考慮されず、符号付きまたは符号なしの int 型のみがビット フィールドに使用されていることを前提としています (ルール 6.4)。

次の場合、違反は報告されません。

  • 暗黙的な変換が型の拡大であり、整数のときは符号属性が変更されない

  • 式が引数式または return 式である

次のすべてに該当する場合、違反は報告されません。

  • 暗黙的な変換が定数式に適用され、型の拡大であり、整数のときは符号属性が変更される可能性がある

  • 変換で定数値の表現または操作の結果が変更されない

  • 式が引数式、return 式または非ビット演算子のオペランド式である

ポインターを含む演算に対しては違反は報告されません。

あまりにも多くの違反にフラグ設定されるのを避けるため、このような場合には定数の変換は報告されません。定数をオリジナルの型でも変換後の型でも表現できる場合、変換はほとんど問題になりません。

10.2

The value of an expression of floating type shall not be implicitly converted to a different type if

  • it is not a conversion to a wider floating type, or

  • the expression is complex, or

  • the expression is a function argument, or

  • the expression is a return expression

  • Implicit conversion of the expression from XX to XX that is not a wider floating type.

  • Implicit conversion of the binary ? right hand operand from XX to XX, but it is a complex expression.

  • Implicit conversion of the binary ? right hand operand from XX to XX that is not a wider floating type or Implicit conversion of the binary ? left hand operand from XX to XX, but it is a complex expression.

  • Implicit conversion of complex floating expression from XX to XX.

  • Implicit conversion of floating expression of XX type in function return whose expected type is XX.

  • Implicit conversion of floating expression of XX type as argument of function whose corresponding parameter type is XX.

ANSI C 基本データ型の順序 (float、double) は、T2 が T1 の右側にある場合は T2 が T1 よりも大きいか、T2 = T1 であることを意味します。

次の場合、違反は報告されません。

  • 暗黙的な変換が型の拡大である

  • 式が引数式または return 式である

10.3

The value of a complex expression of integer type may only be cast to a type that is narrower and of the same signedness as the underlying type of the expression

Complex expression of underlying type XX may only be cast to narrower integer type of same signedness, however the destination type is XX.

  • 複合式の結果が、異なる実質的な型またはより範囲が広い実質的な型にキャストされる場合に限り、ルール チェッカーでは欠陥を報告します。

    たとえば、この例では、i への最初の代入では違反が示されますが、2 番目の代入では示されません。最初の代入では、複合式 i+1 が符号付き型から符号なし型に直接キャストされています。2 番目の代入では、まず複合式が同じ型にキャストされ、次にその結果が別の型にキャストされています。

    typedef int int32_T;
    typedef unsigned char uint8_T; 
    ...
    ...
    int32_T i;
    i = (uint8_T)(i+1); /* Noncompliant */
    i = (uint8_T)((int32_T)(i+1));
     /* Compliant */

  • ANSI C 基本データ型の順序 (符号付きの char、short、int、long) は、T2 が T1 の右側にある場合は T1 が T2 よりも小さいか、T1 = T2 であることを意味します。符号なしの基本データ型にも同じ方法が適用されます。

  • bool 型または enum 型の式は、int 型を潜在型としてもちます。

  • プレーンの char 型は、符号付きの基となる型をもつことも、符号なしの潜在型をもつこともあります (ターゲット構成またはオプション設定に依存)。

  • struct.bitfield の単純な式の潜在型はビット フィールドの定義で使用される基本データ型です。ビット フィールドの幅は考慮されず、符号付きまたは符号なし int 型のみがビット フィールドに使用されていることを前提としています (Rule 6.4)。

10.4

The value of a complex expression of float type may only be cast to narrower floating type

Complex expression of XX type may only be cast to narrower floating type, however the destination type is XX.

ANSI C 基本データ型の順序 (float、double) は、T2 が T1 の右側にある場合は T1 が T2 よりも小さいか、T2 = T1 であることを意味します。

10.5

If the bitwise operator ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand

Bitwise [<<|~] is applied to the operand of underlying type [unsigned char|unsigned short], the result shall be immediately cast to the underlying type.

 
10.6

The “U” suffix shall be applied to all constants of unsigned types

No explicit 'U suffix on constants of an unsigned type.

値および基本データ型 (8 進、10 進または 16 進) から決定される型が符号なしであり、接尾辞 u または U がない場合、警告が生成されます。

たとえば、int データ型と long int データ型のサイズが 32 ビットである場合、コーディング ルール チェッカーで次の行に対するルール 10.6 の違反が報告されます。

int a = 2147483648;

intlong int が同じサイズでない場合、10 進数の定数と 16 進数の定数は異なります。

ポインター型変換

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
11.1

Conversion shall not be performed between a pointer to a function and any type other than an integral type

Conversion shall not be performed between a pointer to a function and any type other than an integral type.

関数ポインターを含むキャストおよび暗黙的な変換です。

NULL または (void*)0 からのキャストまたは暗黙的な変換では、警告は出力されません。

11.2

Conversion shall not be performed between a pointer to an object and any type other than an integral type, another pointer to an object type or a pointer to void

Conversion shall not be performed between a pointer to an object and any type other than an integral type, another pointer to an object type or a pointer to void.

修飾子が失われる場合も警告があります。

このルールは ISO/IEC TS 17961 ID alignconv に対応しています。

11.3

A cast should not be performed between a pointer type and an integral type

A cast should not be performed between a pointer type and an integral type.

ゼロ定数は例外です。すべての変換に適用されます。

このルールは ISO/IEC TS 17961 ID alignconv に対応しています。

11.4

A cast should not be performed between a pointer to object type and a different pointer to object type.

A cast should not be performed between a pointer to object type and a different pointer to object type.

 
11.5

A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer

A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer

すべての変換に適用されます。

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
12.1

Limited dependence should be placed on C's operator precedence rules in expressions

Limited dependence should be placed on C's operator precedence rules in expressions

 
12.2The value of an expression shall be the same under any order of evaluation that the standard permits.
  • The value of 'sym' depends on the order of evaluation.

  • The value of volatile 'sym' depends on the order of evaluation because of multiple accesses.

ルール 12.2 のチェックでは、ブール値が生成される式で代入を使用していないこと (ルール 13.1) を前提としています。

式は、シンボルの単純な式です。i = i++; は違反ですが、tab[2] = tab[2]++; は違反ではありません。

12.3

The sizeof operator should not be used on expressions that contain side effects.

The sizeof operator should not be used on expressions that contain side effects.

volatile アクセスについての警告はありません。

12.4

The right hand operand of a logical && or || operator shall not contain side effects.

The right hand operand of a logical && or || operator shall not contain side effects.

volatile アクセスについての警告はありません。

12.5

The operands of a logical && or || shall be primary-expressions.

  • operand of logical && is not a primary expression

  • operand of logical || is not a primary expression

  • The operands of a logical && or || shall be primary-expressions.

前処理時に、#if 命令の式でこのルールの違反が検出されます。

結合性による (a && b && c)、(a || b || c) は許容される例外です。

12.6

Operands of logical operators (&&, || and !) should be effectively Boolean.Expression that are effectively Boolean should not be used as operands to operators other than (&&, || or !)

  • Operand of '!' logical operator should be effectively Boolean.

  • Left operand of '%s' logical operator should be effectively Boolean.

  • Right operand of '%s' logical operator should be effectively Boolean.

  • %s operand of '%s' is effectively Boolean.Boolean should not be used as operands to operators other than '&&', '||', '!', '=', '==', '!=' and '?:'.

論理演算子のオペランドは boolean データ型であることが必要です。C 標準では boolean データ型を明示的には定義していませんが、boolean データ型の使用を暗黙的に前提としています。

一部の演算子は boolean 形式の式を返すことがあります ((var == 0) など)。

以下のコードについて考えます。

unsigned char flag;
if (!flag)

ルール チェッカーにより、ルール 12.6 の違反が報告されます。

Operand of '!' logical
operator should be 
effectively Boolean.
オペランド flag は boolean ではなく、unsigned char です。

ルール 12.6 に準拠するには、次のどちらかのようにコードを書き換えなければなりません。

if (!( flag != 0))
または
if (flag == 0)

オプション -boolean-types を使用した場合、生成される警告の数が増えることも、減ることもあります。

12.7

Bitwise operators shall not be applied to operands whose underlying type is signed

  • [~/Left Shift/Right shift/&] operator applied on an expression whose underlying type is signed.

  • Bitwise ~ on operand of signed underlying type XX.

  • Bitwise [<<|>>] on left hand operand of signed underlying type XX.

  • Bitwise [& | ^] on two operands of s

次の場合、整数の潜在型は符号付きになります。

  • 接尾辞 u または U をもたない

  • 64 ビット符号付き数に十分収まるくらい小さい

12.8

The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left hand operand.

  • shift amount is negative

  • shift amount is bigger than 64

  • Bitwise [<< >>] count out of range [0 ..X] (width of the underlying type XX of the left hand operand - 1)..

プリプロセッサ命令で操作される数値は 64 ビット幅であることから、有効なシフト範囲は 0 ~ 63 です。

このチェックは、フィールド幅、または基本データ型が複合式内にある場合その幅の、ビット フィールドにも適用されます。

12.9

The unary minus operator shall not be applied to an expression whose underlying type is unsigned.

  • Unary - on operand of unsigned underlying type XX.

  • Minus operator applied to an expression whose underlying type is unsigned

次の場合、整数の潜在型は符号付きになります。

  • 接尾辞 u または U をもたない

  • 64 ビット符号付き数に十分収まるくらい小さい

12.10

The comma operator shall not be used.

The comma operator shall not be used.

 
12.11Evaluation of constant unsigned expression should not lead to wraparound.

Evaluation of constant unsigned integer expressions should not lead to wrap-around.

 
12.12The underlying bit representations of floating-point values shall not be used.The underlying bit representations of floating-point values shall not be used.

次の場合に警告されます。

  • 浮動小数点型ポインターが別のデータ型へのポインターとしてキャストされている。浮動小数点型ポインターを void へのポインターとしてキャストしても、警告は生成されません。

  • 浮動小数点型が別のデータ型でパックされている。以下に例を示します。

    union {
     float f;
     int i;
    } …
    

12.13

The increment (++) and decrement (--) operators should not be mixed with other operators in an expression

The increment (++) and decrement (--) operators should not be mixed with other operators in an expression

++ または -- 演算子はそれのみで使用されていない場合、警告されます。

制御ステートメントの式

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
13.1

Assignment operators shall not be used in expressions that yield Boolean values.

Assignment operators shall not be used in expressions that yield Boolean values.

13.2

Tests of a value against zero should be made explicit, unless the operand is effectively Boolean

Tests of a value against zero should be made explicit, unless the operand is effectively Boolean

整数の定数に対しては警告は出力されません。例: if (2)

オプション -boolean-types を使用した場合、生成される警告の数が増えることも、減ることもあります。

13.3Floating-point expressions shall not be tested for equality or inequality.Floating-point expressions shall not be tested for equality or inequality.直接的なテストに対する警告です。
13.4The controlling expression of a for statement shall not contain any objects of floating typeThe controlling expression of a for statement shall not contain any objects of floating typeインデックス for が変数シンボルである場合、浮動小数点型でないことがチェックされます。
13.5The three expressions of a for statement shall be concerned only with loop control
  • 1st expression should be an assignment.

  • Bad type for loop counter (XX).

  • 2nd expression should be a comparison.

  • 2nd expression should be a comparison with loop counter (XX).

  • 3rd expression should be an assignment of loop counter (XX).

  • 3rd expression: assigned variable should be the loop counter (XX).

  • The following kinds of for loops are allowed:

    (a) all three expressions shall be present;

    (b) the 2nd and 3rd expressions shall be present with prior initialization of the loop counter;

    (c) all three expressions shall be empty for a deliberate infinite loop.

for ループ インデックス (V) が変数シンボルであるかどうかがチェックされます。最初の式が存在する場合、V が最後に代入される変数であるかどうかがチェックされます。最初の式が存在する場合、V の代入であるかどうかがチェックされます。2 番目の式が存在する場合、必ず V の比較であるかどうかがチェックされます。3 番目の式が存在する場合、必ず V の代入であるかどうかがチェックされます。
13.6Numeric variables being used within a for loop for iteration counting should not be modified in the body of the loop.Numeric variables being used within a for loop for iteration counting should not be modified in the body of the loop.for ループ インデックスが既知であり、かつ変数シンボルである場合、直接代入のみ検出します。
13.7

Boolean operations whose results are invariant shall not be permitted

  • Boolean operations whose results are invariant shall not be permitted.Expression is always true.

  • Boolean operations whose results are invariant shall not be permitted.Expression is always false.

  • Boolean operations whose results are invariant shall not be permitted.

コンパイル時、チェッカーは少なくとも 1 つの定数オペランドとの比較を行います。Dead code チェッカーおよび Useless if チェッカーを使ってこのルールの一部の違反が報告されます。

enum 変数値が下限と上限の間に収まるかどうかをチェックするときに、ルール違反が発生します。変数を範囲外にインクリメントまたはデクリメントした場合も違反が発生します。たとえば、次の for ループ条件のような場合です。

enum ec {RED, BLUE, GREEN} 
    col;
for(col=RED; col<=GREEN; 
    col++)
{}
enum 変数は、範囲外にインクリメントされたときにラップ アラウンドできる可能性があるため、ループ条件が常に true にある場合があります。ルール違反を回避するには、次の例のように、比較前に enum を整数にキャストします。
enum ec {RED, BLUE, GREEN} 
   col;
for(col=RED; (int)col<=GREEN;
    col++ )
{}

制御フロー

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
14.1

There shall be no unreachable code.

There shall be no unreachable code. 
14.2

All non-null statements shall either have at least one side effect however executed, or cause control flow to change

All non-null statements shall either:

  • have at least one side effect however executed, or

  • cause control flow to change

 
14.3

前処理の前では、null ステートメントはそれ自体のみが 1 行の中に現れなければなりません。ただし、null ステートメントに続く最初の文字が空白文字の場合は、その後にコメントを記述できます。

A null statement shall appear on a line by itself

';' は、その行の最初の文字である場合 (コメントを除く)、null ステートメントと見なされます。次の場合、このルールに違反します。

  • 同じ行の前方にコメントがある

  • 直後にコメントがある

  • 同じ行で ';' の後にコメント以外の記述がある

14.4

The goto statement shall not be used.

The goto statement shall not be used.

 
14.5

The continue statement shall not be used.

The continue statement shall not be used.

 
14.6

For any iteration statement there shall be at most one break statement used for loop termination

For any iteration statement there shall be at most one break statement used for loop termination

 
14.7

A function shall have a single point of exit at the end of the function

A function shall have a single point of exit at the end of the function

 
14.8

The statement forming the body of a switch, while, do while or for statement shall be a compound statement

  • The body of a do while statement shall be a compound statement.

  • The body of a for statement shall be a compound statement.

  • The body of a switch statement shall be a compound statement

 
14.9

An if (expression) construct shall be followed by a compound statement.The else keyword shall be followed by either a compound statement, or another if statement

  • An if (expression) construct shall be followed by a compound statement.

  • The else keyword shall be followed by either a compound statement, or another if statement

 
14.10

All if else if constructs should contain a final else clause.

All if else if constructs should contain a final else clause.

 

switch ステートメント

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
15.0

The MISRA C switch syntax shall be used.

switch statements syntax normative restrictions.

最初の switch case の前にある宣言またはステートメントについて警告します。

switch case の本体にある label または jump ステートメントについて警告します。

次の例では、このルールがログ ファイルの行 3 に表示されています。

1 ...
2 switch(index) {
3  var = var + 1; 
// RULE 15.0 
// violated
4case 1: ...

switch ステートメントと最初の case の間にあるコードは、Polyspace によってデッド コードとしてチェックされます。これは ANSI 規格の動作に従います。

このルールは、生成されたコードでは MISRA C:2004 ルールの必要ルールと見なされません。生成されたコードでルール 15.0 の違反を見つけても、それがこのグループの後のルールに同時に違反しない場合は、適切なコメントでその違反を正当化します。

15.1

A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement

A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement

 
15.2

An unconditional break statement shall terminate every non-empty switch clause

An unconditional break statement shall terminate every non-empty switch clause

準拠しない case 句ごとに警告が生成されます。

15.3

The final clause of a switch statement shall be the default clause

The final clause of a switch statement shall be the default clause

 
15.4

A switch expression should not represent a value that is effectively Boolean

A switch expression should not represent a value that is effectively Boolean

オプション -boolean-types の使用により生成される警告の数が増える場合があります。

15.5

Every switch statement shall have at least one case clause

Every switch statement shall have at least one case clause

 

関数

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
16.1

Functions shall not be defined with variable numbers of arguments.

Function XX should not be defined as varargs.

 
16.2

Functions shall not call themselves, either directly or indirectly.

Function %s should not call itself.

チェッカーは、それ自体を直接的または間接的に呼び出すそれぞれの関数について報告します。1 つの再帰サイクルに複数の関数が関与している場合でも、それぞれの関数が個別に報告されます。

再帰サイクルの総数は、コード複雑度メトリクス [再帰の数] を使用して計算できます。

16.3

Identifiers shall be given for all of the parameters in a function prototype declaration.

Identifiers shall be given for all of the parameters in a function prototype declaration.

ルール 8.6 に違反していないことを前提としています。

16.4The identifiers used in the declaration and definition of a function shall be identical.The identifiers used in the declaration and definition of a function shall be identical.

ルール 8.88.1 および 16.3 に違反していないことを前提としています。

すべての出現箇所が検出されます。

16.5

Functions with no parameters shall be declared with parameter type void.

Functions with no parameters shall be declared with parameter type void.

定義もチェックされます。

16.6The number of arguments passed to a function shall match the number of parameters.
  • Too many arguments to XX.

  • Insufficient number of arguments to XX.

ルール 8.1 に違反していないことを前提としています。

このルールは ISO/IEC TS 17961 ID argcomp に対応しています。

16.7

A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object.

Pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object.

const のポインター パラメーターが、指しているオブジェクトを変更する目的で使用されていないか、const ポインター パラメーターを指定して宣言されている関数の呼び出しに渡される場合、警告が生成されます。

16.8

All exit paths from a function with non-void return type shall have an explicit return statement with an expression.

Missing return value for non-void function XX.

非 void 関数が、式をもつ無条件の return で終了していない場合、警告が生成されます。

16.9

A function identifier shall only be used with either a preceding &, or with a parenthesized parameter list, which may be empty.

Function identifier XX should be preceded by a & or followed by a parameter list.

 
16.10

If a function returns error information, then that error information shall be tested.

If a function returns error information, then that error information shall be tested.

チェッカーは、戻り値が使用されない場合や void 型に明示的にキャストされない場合に void 以外の戻り値で関数にフラグを設定します。

ただし、関数の memcpymemsetmemmovestrcpystrncpystrcatstrncat は、最初の引数へのポインターを返すだけなので、フラグは設定されません。

ポインターと配列

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
17.1

Pointer arithmetic shall only be applied to pointers that address an array or array element.

Pointer arithmetic shall only be applied to pointers that address an array or array element.

 
17.2Pointer subtraction shall only be applied to pointers that address elements of the same arrayPointer subtraction shall only be applied to pointers that address elements of the same array.null ポインターまたは別の配列内の要素を指しているポインターを減算すると、Polyspace は違反を報告します。
17.3

>, >=, <, <= shall not be applied to pointer types except where they point to the same array.

>, >=, <, <= shall not be applied to pointer types except where they point to the same array.

null ポインターまたは別の配列内の要素を指しているポインターを比較すると、Polyspace は違反を報告します。比較の関係演算子は ><>=、および <= です。
17.4Array indexing shall be the only allowed form of pointer arithmetic.Array indexing shall be the only allowed form of pointer arithmetic.

以下に対する警告です。

  • ポインターの演算 (p+II+p および p-Ip はポインター、I は整数)。

  • 非配列ポインターの配列インデックス付け。

17.5A type should not contain more than 2 levels of pointer indirectionA type should not contain more than 2 levels of pointer indirection 
17.6The address of an object with automatic storage shall not be assigned to an object that may persist after the object has ceased to exist.Pointer to a parameter is an illegal return value.Pointer to a local is an illegal return value.

グローバル変数へのアドレスの代入で、ローカル変数のアドレスまたはパラメーターのアドレスが返ると警告されます。

このルールは ISO/IEC TS 17961 ID accfree に対応しています。

構造体と共用体

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
18.1

All structure or union types shall be complete at the end of a translation unit.

All structure or union types shall be complete at the end of a translation unit.

不完全な構造体または共用体の宣言には警告が行われます。

18.2

An object shall not be assigned to an overlapping object.

  • An object shall not be assigned to an overlapping object.

  • Destination and source of XX overlap, the behavior is undefined.

 
18.4

Unions shall not be used

Unions shall not be used.

 

プリプロセッサ命令

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
19.1

#include statements in a file shall only be preceded by other preprocessors directives or comments

#include statements in a file shall only be preceded by other preprocessors directives or comments

A message is displayed when a #include directive is preceded by other things than preprocessor directives, comments, spaces or “new lines”.

19.2

Nonstandard characters should not occur in header file names in #include directives

  • A message is displayed on characters ', " or /* between < and > in #include <filename>

  • A message is displayed on characters ', or /* between " and " in #include "filename"

 
19.3

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

  • '#include' expects "FILENAME" or <FILENAME>

  • `#include_next' expects "FILENAME" or <FILENAME>

 
19.4C macros shall only expand to a braced initializer, a constant, a parenthesized expression, a type qualifier, a storage class specifier, or a do-while-zero construct.

Macro `<name>' does not expand to a compliant construct.

マクロ定義は、以下に展開される場合、このルールに違反していないと見なされます。

  • 中かっこで囲まれた構造 (初期化子とは限らない)

  • 小かっこで囲まれた構造 (式とは限らない)

  • 数値

  • 文字定数

  • 文字列定数 (文字列フィールドの引数とリテラル文字列の連結の結果でもよい)

  • 次のキーワード: typedef、extern、static、auto、register、const、volatile、__asm__ and __inline__

  • do-while-zero 構造

19.5

Macros shall not be #defined and #undefd within a block.

  • Macros shall not be #define’d within a block.

  • Macros shall not be #undef’d within a block.

 
19.6

#undef shall not be used.

#undef shall not be used.

 
19.7

A function should be used in preference to a function like-macro.

A function should be used in preference to a function like-macroすべての関数形式のマクロ定義のメッセージ。
19.8

A function-like macro shall not be invoked without all of its arguments

  • arguments given to macro '<name>'

  • macro '<name>' used without args.

  • macro '<name>' used with just one arg.

  • macro '<name>' used with too many (<number>) args.

 
19.9

Arguments to a function-like macro shall not contain tokens that look like preprocessing directives.

Macro argument shall not look like a preprocessing directive.

マクロの引数内 (文字列定数または文字定数の外部) で '#' 文字が使用されている場合、このルールが違反として検出されます。

19.10

In the definition of a function-like macro each instance of a parameter shall be enclosed in parentheses unless it is used as the operand of # or ##.

Parameter instance shall be enclosed in parentheses.

x がマクロのパラメーターである場合、# および ## 演算子のオペランドとしての x のインスタンス #x##x および x## に対しては、警告は生成されません。それ以外の場合は、x を小かっこで囲む必要があります。

パラメーターが関数または関数形式マクロの引数として再利用される場合、警告は生成されません。たとえば、パラメーター x について考えます。x(x) または (x, または ,x) または ,x, のように記述されている場合、警告は生成されません。

19.11

All macro identifiers in preprocessor directives shall be defined before use, except in #ifdef and #ifndef preprocessor directives and the defined() operator.

'<name>' is not defined.

 
19.12

There shall be at most one occurrence of the # or ## preprocessor operators in a single macro definition.

More than one occurrence of the # or ## preprocessor operators.

 
19.13

The # and ## preprocessor operators should not be used

Message on definitions of macros using # or ## operators

 
19.14

The defined preprocessor operator shall only be used in one of the two standard forms.

'defined' without an identifier.

 
19.15Precautions shall be taken in order to prevent the contents of a header file being included twice.Precautions shall be taken in order to prevent multiple inclusions.

ヘッダー ファイルの形式

#ifndef <control macro>
#define <control macro> 
<contents> #endif

または

#ifndef <control macro>
#error ...
#else 
#define <control macro> 
<contents> #endif

この場合、複数回インクルードされないように安全対策が講じられていると見なされます。それ以外の場合は、この MISRA ルールの違反が検出されます。

19.16

Preprocessing directives shall be syntactically meaningful even when excluded by the preprocessor.

directive is not syntactically meaningful.

 
19.17

All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related.

  • '#elif' not within a conditional.

  • '#else' not within a conditional.

  • '#elif' not within a conditional.

  • '#endif' not within a conditional.

  • unbalanced '#endif'.

  • unterminated '#if' conditional.

  • unterminated '#ifdef' conditional.

  • unterminated '#ifndef' conditional.

 

標準ライブラリ

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
20.1

Reserved identifiers, macros and functions in the standard library, shall not be defined, redefined or undefined.

  • The macro '<name> shall not be redefined.

  • The macro '<name> shall not be undefined.

 
20.2

The names of standard library macros, objects and functions shall not be reused.

Identifier XX should not be used.

標準ライブラリのマクロ、オブジェクトおよび関数に一致する名前をもつマクロが定義されている場合、違反されたものとして検出されるルールは 20.1 です。

仮定義は定義と見なされます。ファイル スコープのオブジェクトの場合、仮定義は次のような宣言となります。

  • 初期化子をもたない。

  • ストレージ クラス指定子をもたないか static 指定子をもつ

20.3

The validity of values passed to library functions shall be checked.

Validity of values passed to library functions shall be checked

次のすべてに該当する場合、ライブラリ関数の呼び出しの引数に対して、警告が生成されます。

  • 引数がローカル変数である

  • 最後の代入とライブラリ関数の呼び出しの間でローカル変数がテストされていない

  • ライブラリ関数が一般的な数学関数である

  • ライブラリ関数の対応するパラメーターの入力定義域に制限がある

ライブラリ関数は、sqrttanpowloglog10fmodacosasinacoshatanhatan2 のいずれかです。

数学関数からなるカスタム ライブラリを使用することもあります。カスタム ライブラリ関数の領域と範囲が、標準ライブラリに含まれる別の関数の領域と範囲と同じであれば、そのカスタム ライブラリ関数をチェックするように、このチェッカーを拡張できます。標準ライブラリ関数用の Bug Finder チェッカーのカスタム ライブラリへの拡張を参照してください。

入力値が不明であり、入力のサブセットのみがエラーの原因として考えられる場合、既定の Bug Finder 解析ではこのルールに対する違反が報告されない場合があります。特定のシステム入力値を原因とする違反の有無をチェックするには、より厳密な Bug Finder 解析を実行してください。特定のシステム入力値から欠陥を見つけるための Bug Finder チェッカーの拡張を参照してください。

既定では、Bug Finder 解析は無限大と NaNs を認識しません。結果が無限大および NaNs になる演算には、欠陥としてフラグが設定される可能性があります。コードで無限大および NaN の値を処理するには、オプション [非有限の浮動小数点を検討] (-allow-non-finite-floats) を使用します。

20.4

Dynamic heap memory allocation shall not be used.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

動的ヒープ メモリ割り当て関数が実質的なマクロであり、このマクロがコードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。

20.5

The error indicator errno shall not be used

The error indicator errno shall not be used

ルール 20.2 に違反していないことを前提としています。

20.6

The macro offsetof, in library <stddef.h>, shall not be used.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

ルール 20.2 に違反していないことを前提としています。

20.7

The setjmp macro and the longjmp function shall not be used.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

関数 longjmp が実質的なマクロであり、マクロがコードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。

20.8

The signal handling facilities of <signal.h> shall not be used.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

信号機能が実質的なマクロであり、そのマクロがコードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。

20.9

The input/output library <stdio.h> shall not be used in production code.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

入出力ライブラリ関数が実質的なマクロであり、コードに展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。

20.10

The library functions atof, atoi and atoll from library <stdlib.h> shall not be used.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

関数 atof、atoi および atoll が実質的なマクロであり、展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。

20.11

The library functions abort, exit, getenv and system from library <stdlib.h> shall not be used.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

関数 abort、exit、getenv および system が実質的なマクロであり、展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。

20.12

The time handling functions of library <time.h> shall not be used.

  • The macro '<name> shall not be used.

  • Identifier XX should not be used.

時間処理関数が実質的なマクロとして展開される場合、このルールに違反したものとして検出されます。ルール 20.2 に違反していないことを前提としています。

実行時の失敗

番号MISRA 定義レポート ファイル メッセージPolyspace 実装
21.1

Minimization of runtime failures shall be ensured by the use of at least one of:

  • static verification tools/techniques;

  • dynamic verification tools/techniques;

  • explicit coding of checks to handle runtime faults.

  

サポートされていない MISRA C:2004 および MISRA AC AGC ルール

Polyspace コーディング ルール チェッカーでは、以下の MISRA C:2004 コーディング ルールはチェックされません。これらのルールは Polyspace ソフトウェアの範囲外であるため、強制することはできません。これらは、MISRA ルールのドキュメンテーション、動的局面、機能的側面に関わるものです。「その他の情報」列には、各ルールがチェックされない理由が示されています。

環境

ルール説明その他の情報
1.2 (必要)

No reliance shall be placed on undefined or unspecified behavior

データの動的な性質が考慮されない限り、静的にチェックすることはできません。

1.3 (必要)

Multiple compilers and/or languages shall only be used if there is a common defined interface standard for object code to which the language/compilers/assemblers conform.

これはプロセス ルールのメソッドです。

1.4 (必要)

The compiler/linker/Identifiers (internal and external) shall not rely on significance of more than 31 characters.Furthermore the compiler/linker shall be checked to ensure that 31 character significance and case sensitivity are supported for external identifiers.

このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。

1.5 (推奨)

Floating point implementations should comply with a defined floating point standard.

このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。

ドキュメンテーション

ルール説明その他の情報
3.1 (必要)

All usage of implementation-defined behavior shall be documented.

このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。処理系定義の構造に対して行われた選択に応じて、未定義の動作に基づいてエラーが検出されます。

3.2 (必要)

The character set and the corresponding encoding shall be documented.

このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。

3.3 (推奨)

The implementation of integer division in the chosen compiler should be determined, documented and taken into account.

このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。

3.5 (必要)

The implementation-defined behavior and packing of bitfields shall be documented if being relied upon.

このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。

3.6 (必要)

All libraries used in production code shall be written to comply with the provisions of this document, and shall have been subject to appropriate validation.

このルールを確認するには、コンパイラのドキュメンテーションをチェックしてください。

構造体と共用体

ルール説明その他の情報
18.3 (必要)

An area of memory shall not be reused for unrelated purposes.

"目的" とは機能設計に関する事柄です。