Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

MISRA C:2012 準拠の概要表

MathWorks® は、Simulink® モデルおよび Stateflow® チャートから Embedded Coder® で生成された C コードを MISRA C:2012 コーディング規約に照らして評価しています。この取り組みの結果を、以下の準拠概要表で参照できます。これらの表では、準拠を実現するために使用する方法も示します。

  • 準拠: ルール/命令への準拠は、コード生成プロセス、モデリング ガイドライン、またはモデル アドバイザー チェックに従うことで実現します。該当する場合は、命令またはルールを満たすために実行できる準拠方法やアクションに関連する情報を示す説明メモがあります。

  • 逸脱: ルールまたは命令は準拠していません。

これらの表は、『MISRA C:2012 Guidelines for the Use of C Language in Critical Systems』ドキュメントの 5.3 節に従って必要に応じてプロジェクトの MISRA C:2012 準拠表明を準備する際に使用できます。これらの表は、公開されている MISRA C:2012 メイン ドキュメント、MISRA C:2012 Amendment 1、および MISRA C:2012 Amendment 2 と一致します。表内のカテゴリは、自動生成コード用に記載された MISRA ガイドラインの付録 E に基づいています。必須カテゴリと必要カテゴリの場合のみ使用できます (勧告カテゴリと可読性カテゴリの場合は使用できません)。

メモ

Embedded Coder から生成されたコードは、これらのコーディング ガイドラインの大部分に適合します。これらの表のルール/命令に準拠していないステータスは、自動生成コード用に特定された必須カテゴリおよび必要カテゴリに分類されません。

"実装" MISRA C:2012 命令

命令説明カテゴリ準拠
D1.1Any implementation-defined behaviour on which the output of the program depends shall be documented and understood.必要

準拠:

"コンパイルとビルド" MISRA C:2012 命令

命令説明カテゴリ準拠
D2.1All source files shall compile without any compilation errors.必要準拠

"要件のトレーサビリティ" MISRA C:2012 命令

命令説明カテゴリ準拠
D3.1All code shall be traceable to documented requirements.必要

準拠:

"コード設計" MISRA C:2012 命令

命令a説明カテゴリ準拠
D4.1Run-time failures shall be minimized.必要

準拠:

D4.3Assembly language shall be encapsulated and isolated.必要

準拠:

D4.6typedefs that indicate size and signedness should be used in place of the basic numerical types.勧告

適用不可。

D4.7bIf a function returns error information, then that error information shall be tested.必要

準拠:

逸脱:

D4.10Precautions shall be taken in order to prevent the contents of a header file being included more than once.必要準拠
D4.11The validity of values passed to library functions shall be checked.必要

準拠:

D4.12Dynamic memory allocation shall not be used.必要

準拠:

D4.14The validity of values received from external sources shall be checked.必要準拠

a Directive 4.14 is from MISRA Amendment 1.

b The Polyspace MISRA C:2012 Checker might flag Directive 4.7 as a Rule 17.7 violation (Polyspace Bug Finder) for user-defined functions when there is no knowledge about whether the return value contains error information.

"標準 C 環境" MISRA C:2012 ルール

ルールa説明カテゴリ準拠
1.1The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits.必要準拠
1.3There shall be no occurrence of undefined or critical unspecified behaviour.必要準拠
1.4Emergent language features shall not be used.必要準拠

a Rule 1.4 is from MISRA Amendment 2.

"未使用コード" MISRA C:2012 ルール

ルール説明カテゴリ準拠
2.1A project shall not contain unreachable code.必要

準拠:

2.2There shall be no dead code.必要準拠

"コメント" MISRA C:2012 ルール

ルール説明カテゴリ準拠
3.1The character sequences /* and // shall not be used within a comment.必要

準拠:

3.2Line-splicing shall not be used in // comments.必要準拠

"文字セットと字句規則" MISRA C:2012 ルール

ルール説明カテゴリ準拠
4.1Octal and hexadecimal escape sequences shall be terminated.必要準拠

"識別子" MISRA C:2012 ルール

ルール説明カテゴリa準拠
5.1External identifiers shall be distinct.必要

準拠:

5.2Identifiers declared in the same scope and name space shall be distinct.必要

準拠:

5.3An identifier declared in an inner scope shall not hide an identifier declared in an outer scope.勧告非準拠
5.4Macro identifiers shall be distinct.必要

準拠:

5.5Identifiers shall be distinct from macro names.必要

準拠:

5.6A typedef name shall be a unique identifier.必要

準拠:

5.7A tag name shall be a unique identifier.必要

準拠:

5.8Identifiers that define objects or functions with external linkage shall be unique.必要

準拠:

a Guideline identifies Rule 5.3 as Required for manually generated code.

"型" MISRA C:2012 ルール

ルール説明カテゴリ準拠
6.1Bit-fields shall only be declared with an appropriate type.必要

準拠:

6.2Single-bit named bit fields shall not be of a signed type.必要

準拠:

"リテラルと定数" MISRA C:2012 ルール

ルール説明カテゴリa準拠
7.1Octal constants shall not be used.勧告準拠
7.2A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type.可読性準拠
7.3The lowercase character "l" shall not be used in a literal suffix.可読性準拠
7.4A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char".必要準拠

a Guideline identifies Rule 7.1, 7.2, and 7.3 as Required for manually generated code.

"宣言と定義" MISRA C:2012 ルール

ルール説明カテゴリa準拠
8.1Types shall be explicitly specified.必要準拠
8.2Function types shall be in prototype form with named parameters.必要準拠
8.3All declarations of an object or function shall use the same names and type qualifiers.必要準拠
8.4A compatible declaration shall be visible when an object or function with external linkage is defined.勧告非準拠
8.5An external object or function shall be declared once in one and only one file.勧告非準拠
8.6An identifier with external linkage shall have exactly one external definition.必要準拠
8.8The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage.必要準拠
8.10An inline function shall be declared with the static storage class.必要準拠
8.12Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique.必要

準拠:

8.14The restrict type qualifier shall not be used.勧告準拠

a Guideline identifies Rule 8.4, 8.5, and 8.14 as Required for manually generated code.

"初期化" MISRA C:2012 ルール

ルール説明カテゴリa準拠
9.1The value of an object with automatic storage duration shall not be read before it has been set.必須

準拠:

9.2The initializer for an aggregate or union shall be enclosed in braces.可読性非準拠
9.3Arrays shall not be partially initialized.可読性非準拠
9.4An element of an object shall not be initialized more than once.必要準拠
9.5Where designated initializers are used to initialize an array object the size of the array shall be specified explicitly.可読性準拠

a Guideline identifies Rule 9.2, 9.3, and 9.5 as Required for manually generated code.

"実質的な型モデル" MISRA C:2012 ルール

ルール説明カテゴリa準拠
10.1Operands shall not be of an inappropriate essential type.勧告非準拠
10.2Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations.勧告準拠
10.3The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.勧告準拠
10.4Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category.勧告非準拠
10.6The value of a composite expression shall not be assigned to an object with wider essential type.勧告非準拠
10.7If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type.勧告非準拠
10.8The value of a composite expression shall not be cast to a different essential type category or a wider essential type.勧告非準拠

a Guideline identifies Rule 10.1, 10.2, 10.3, 10.4, 10.6, 10.7, and 10.8 as Required for manually generated code.

"ポインター型の変換" MISRA C:2012 ルール

ルール説明カテゴリa準拠
11.1Conversions shall not be performed between a pointer to a function and any other type.必要準拠
11.2Conversions shall not be performed between a pointer to an incomplete type and any other type.必要準拠
11.3A cast shall not be performed between a pointer to object type and a pointer to a different object type.必要

準拠:

11.6A cast shall not be performed between pointer to void and an arithmetic type.必要準拠
11.7A cast shall not be performed between pointer to object and a non-integer arithmetic type.必要準拠
11.8A cast shall not remove any const or volatile qualification from the type pointed to by a pointer.必要

準拠:

11.9The macro NULL shall be the only permitted form of integer null pointer constant.可読性非準拠

a Guideline identifies Rule 11.9 as Required for manually generated code.

"式" MISRA C:2012 ルール

ルールa説明カテゴリ準拠
12.2The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand. 必要準拠
12.5The sizeof operator shall not have an operand which is a function parameter declared as "array of type".必須準拠

a Rule 12.5 is from MISRA Amendment 1.

"副作用" MISRA C:2012 ルール

ルール説明カテゴリ準拠
13.1Initializer lists shall not contain persistent side effects.必要準拠
13.2The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders.必要

準拠:

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

準拠:

逸脱:

13.6The operand of the sizeof operator shall not contain any expression which has potential side effects.必須準拠

"コントロール ステートメントの式" MISRA C:2012 ルール

ルール説明カテゴリa準拠
14.1A loop counter shall not have essentially floating type.勧告非準拠
14.2A for loop shall be well-formed.可読性

準拠:

14.3Controlling expressions shall not be invariant.必要

準拠:

14.4The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type.勧告非準拠

a Guideline identifies Rule 14.1, 14.2, and 14.4 as Required for manually generated code.

"制御フロー" MISRA C:2012 ルール

ルール説明カテゴリa準拠
15.2The goto statement shall jump to a label declared later in the same function.勧告準拠
15.3Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement.勧告準拠
15.6The body of an iteration-statement or a selection-statement shall be a compound-statement.必要準拠
15.7All if ... else if constructs shall be terminated with an else statement.可読性準拠

a Guideline identifies Rule 15.2, 15.3, and 15.7 as Required for manually generated code.

"switch ステートメント" MISRA C:2012 ルール

ルール説明カテゴリa準拠
16.1All switch statements shall be well-formed.勧告非準拠
16.2A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.勧告準拠
16.3An unconditional break statement shall terminate every switch-clause.勧告準拠
16.4Every switch statement shall have a default label.勧告

準拠:

16.5A default label shall appear as either the first or the last switch label of a switch statement.勧告準拠
16.6Every switch statement shall have at least two switch-clauses.勧告準拠
16.7A switch-expression shall not have essentially Boolean type.勧告準拠

a Guideline identifies Rule 16.1, 16.2, 16.3, 16.4, 16.5, 16.6, and 16.7 as Required for manually generated code.

"関数" MISRA C:2012 ルール

ルール説明カテゴリa準拠
17.1The features of <stdarg.h> shall not be used.必要準拠
17.2Functions shall not call themselves, either directly or indirectly.必要

準拠:

17.3A function shall not be declared implicitly.必須準拠
17.4All exit paths from a function with non-void return type shall have an explicit return statement with an expression.必須準拠
17.6The declaration of an array parameter shall not contain the static keyword between the [ ].必須準拠
17.7The value returned by a function having non-void return type shall be used.可読性非準拠

a Guideline identifies Rule 17.7 as Required for manually generated code.

"ポインターと配列" MISRA C:2012 ルール

ルール説明カテゴリ準拠
18.1A pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operand.必要準拠
18.2Subtraction between pointers shall only be applied to pointers that address elements of the same array.必要準拠
18.3The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object.必要準拠
18.6The address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to exist.必要準拠
18.7Flexible array members shall not be declared.必要準拠
18.8Variable-length array types shall not be used.必要準拠

"重複するストレージ" MISRA C:2012 ルール

ルール説明カテゴリ準拠
19.1An object shall not be assigned or copied to an overlapping object.必須準拠

"プリプロセッサ命令" MISRA C:2012 ルール

ルール説明カテゴリ準拠
20.2The ', " or \ characters and the /* or // character sequences shall not occur in a header file name.必要準拠
20.3The #include directive shall be followed by either a <filename> or "filename"sequence.必要準拠
20.4A macro shall not be defined with the same name as a keyword.必要準拠
20.6Tokens that look like a preprocessing directive shall not occur within a macro argument.必要準拠
20.7Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses.必要準拠
20.8The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1.必要準拠
20.9All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #define'd before evaluation.必要準拠
20.11A macro parameter immediately following a # operator shall not immediately be followed by a ## operator.必要準拠
20.12A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators.必要準拠
20.13A line whose first token is # shall be a valid preprocessing directive.必要準拠
20.14All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related.必要準拠

"標準ライブラリ" MISRA C:2012 ルール

ルールa, b説明カテゴリ準拠
21.1#define and #undef shall not be used on a reserved identifier or reserved macro name.必要

準拠:

21.2A reserved identifier or reserved macro name shall not be declared.必要

準拠:

21.3The memory allocation and deallocation functions of <stdlib.h> shall not be used.必要

準拠:

21.4The standard header file <setjmp.h> shall not be used.必要準拠
21.5The standard header file <signal.h> shall not be used.必要準拠
21.6The Standard Library input/output functions shall not be used.必要

準拠:

21.7The Standard Library functions atof, atoi, atol and atoll of <stdlib.h> shall not be used.必要準拠
21.8The Standard Library termination functions of <stdlib.h> shall not be used.必要準拠
21.9The Standard Library functions bsearch and qsort of <stdlib.h> shall not be used.必要準拠
21.10The Standard Library time and date functions shall not be used.必要準拠
21.11The standard header file <tgmath.h> shall not be used.必要準拠
21.13Any value passed to a function in <ctype.h> shall be representable as an unsigned char or be the value EOF.必須準拠
21.14The Standard Library function memcmp shall not be used to compare null terminated strings.必要準拠
21.15The pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers to qualified or unqualified versions of compatible types.必要準拠
21.16The pointer arguments to the Standard Library function memcmp shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum type.必要準拠
21.17Use of the string handling functions from <string.h> shall not result in accesses beyond the bounds of the objects referenced by their pointer parameters.必須準拠
21.18The size_t argument passed to any function in <string.h> shall have an appropriate value.必須準拠
21.19The pointers returned by the Standard Library functions localeconv, getenv, setlocale or, strerror shall only be used as if they have pointer to const-qualified type.必須準拠
21.20The pointer returned by the Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale or strerror shall not be used following a subsequent call to the same function.必須準拠
21.21The Standard Library function system of <stdlib.h> shall not be used.必要準拠

a Rule 21.13, 21.14, 21.15, 21.16, 21.17, 21.18, 21.19, 21.20 is from MISRA Amendment 1.

b Rule 21.21 is from MISRA Amendment 2.

"リソース" MISRA C:2012 ルール

ルールa説明カテゴリ準拠
22.1All resources obtained dynamically by means of Standard Library functions shall be explicitly released.必要準拠
22.2A block of memory shall only be freed if it was allocated by means of a Standard Library function.必須準拠
22.3The same file shall not be open for read and write access at the same time on different streams.必要準拠
22.4There shall be no attempt to write to a stream which has been opened as read-only.必須準拠
22.5A pointer to a FILE object shall not be dereferenced.必須準拠
22.6The value of a pointer to a FILE shall not be used after the associated stream has been closed.必須準拠
22.7The macro EOF shall only be compared with the unmodified return value from any Standard Library function capable of returning EOF.必要準拠
22.8The value of errno shall be set to zero prior to a call to an errno-setting-function.必要準拠
22.9The value of errno shall be tested against zero after calling an errno-setting-function.必要準拠
22.10The value of errno shall only be tested when the last function to be called was an errno-setting-function.必要準拠

a Rule 22.7, 22.8, 22.9, 22.10 is from MISRA Amendment 1.

説明メモ

次の説明メモはMISRA C:2012 準拠の概要表から参照されるものです。

命令 1.1 に関する説明メモ

Embedded Coder の処理系定義の動作については、ランタイム環境オプションの構成を参照してください。コンパイラのドキュメンテーションはスコープ外です。

文字セット エンコードは SavedCharacterEncoding モデル パラメーターを使用して管理します。詳細については、slCharacterEncoding を参照してください。

[モデル コンフィギュレーション パラメーター] ダイアログ ボックスの [ハードウェア実行] ペインで、整数除算方法を構成します。詳細については、ランタイム環境オプションの構成を参照してください。

Embedded Coder は、ユーザーが以下を行うと #pragma を生成します。

どちらの場合も、#pragma の用途をドキュメント化する必要があります。詳細については、Control Data and Function Placement in Memory by Inserting Pragmasを参照してください。

ビットフィールドの生成を有効にするには、次のようにします。

  1. 次のモデル コンフィギュレーション パラメーターのうち少なくとも 1 つを選択します。

  2. 定義済みのビットフィールドを含むカスタム ストレージ クラスを作成します。詳細については、カスタム ストレージ クラス デザイナーを使用したストレージ クラスの作成を参照してください。

モデルで、あるデータ型から別のデータ型への変換が使用されている場合、Polyspace® チェッカーは命令 1.1 の違反を示す場合があります。

MISRA 命令 3.1 に関する説明メモ

要件とモデル要素をリンクできます。このようなリンクを生成された C コードに含めて、要件ドキュメントからモデル要素および生成コードへのトレーサビリティを提供します。詳細については、モデル要素に関連付けられている Requirements Toolbox リンクの表示およびView and Link Requirements in Simulink (Requirements Toolbox)を参照してください。

命令 4.1 に関する説明メモ

Polyspace Bug Finder™ を使用してランタイム エラーを特定でき、Polyspace Code Prover™ を使用してランタイム エラーがないことを証明できます。詳細については、以下を参照してください。

Simulink Design Verifier を使用して、設計エラーをモデル レベルで検出できます。詳細については、モデルにおける設計エラーの解析 (Simulink Design Verifier)を参照してください。

オーバーフロー違反を処理するには、Simulink モデルでのオーバーフローの処理 (Fixed-Point Designer)を参照してください。

命令 4.3 に関する説明メモ

Embedded Coder はアセンブリ言語コードを直接呼び出しません。S-Function、コード置換ライブラリ、Stateflow、および MATLAB® ブロックでアセンブリ言語関数の呼び出しを追加できます。これらの呼び出しはExternal C Functionsの呼び出しとしてドキュメント化します。このような場合、カプセル化を行う必要があります。

詳細については、以下を参照してください。

命令 4.6 に関する説明メモ

Embedded Coder は、基本データ型を命令 4.6 と互換性のある typedef 型に置き換えます。この動作は Embedded Coder の既定の動作であるため、ガイドラインは不要です。詳細については、Replace and Rename Simulink Coder Data Types to Conform to Coding Standardsおよび Typedef を参照してください。

命令 4.11 に関する説明メモ

この命令の要件は以下により満たされます。

入力パラメーターが無効な値を受け取れないことを静的に実証する。

Polyspace Code Prover を使用してパラメーター範囲を解析し、値が範囲外であるために発生するランタイム エラーがないことを証明できます。詳細については、Embedded Coder によって生成されたコードに対する Polyspace 解析の実行 (Polyspace Code Prover)を参照してください。

ルール 2.1 に関する説明メモ

Embedded Coder は、Stateflow のユーザー定義コードをチェックしません。報告される違反に対処する必要があります。

ルール 5.1、5.2、5.4、5.5、5.6、5.7 および 5.8 に関する説明メモ

Embedded Coder は、実装によって設定される文字数を制限するよう構成できます。詳細については、[識別子の最大の長さ] を参照してください。

変数のタイプ (ローカル スコープ変数、グローバル スコープ変数、マクロなど) ごとに一意の名前を確保するには、命名規則を実装します。詳細については、[モデル コンフィギュレーション パラメーター: コード生成識別子] を参照してください。

長い識別子の場合は、共有ユーティリティを使用することをお勧めします。詳細については、共有ユーティリティ コードの生成を参照してください。

ルール 8.12 に関する説明メモ

Embedded Coder は列挙データの使用をサポートしています。列挙の定義に使用するファイルは手動でも自動でも生成できます。Embedded Coder によって生成された列挙を定義するファイルは、設計上 MISRA C:2012 ルール 8.12 に準拠しています。定義ファイルを手動で作成する場合、準拠を確保する必要があります。詳細については、Simulink モデルでの列挙型データの使用を参照してください。

ルール 11.8 に関する説明メモ

モデルで使用しているストレージ クラスに修飾子 Const または Volatile が設定されている場合、Polyspace チェッカーはモデルの生成コードがルール 11.8 に違反していることを示す場合があります。

ルール 13.2 に関する説明メモ

volatile 変数を使用すると、ルール 13.2 に違反する場合があります。

ルール 17.3 および 21.2 に関する説明メモ

モデル コンフィギュレーション パラメーター [ターゲット ハードウェアの命令セット拡張を活用][なし] 以外に設定されている場合、生成されるコードで MISRA C:2012 ルール違反が示される場合があります。