Main Content



識別子、コード スタイルおよびコメントを変更するパラメーターの設定

モデル コンフィギュレーション パラメーターでは、生成コードの外観を設定することができます。コード内のコメントのスタイルの変更、識別子の生成方法の変更、コード スタイルの指定、カスタム ファイルと関数バナーを指定するコード生成テンプレート ファイルの変更を行うことができます。



コード コメントの構成

コード ジェネレーターで生成コードにコメントを挿入する方法は、[コード生成]、[コメント] ペインでパラメーターを変更することによって構成します。

Add Custom Comments for Variables in the Generated Code

Add selected data object property values as a comment in the general code above that data object identifier.

Add Global Comments in the Generated Code

Add global comments to a Simulink® model so that the comment text appears where you specify in the generated files.

Annotate Code for Justifying Polyspace Checks

This example shows how to turn on comments in the generated code that suppress error detection through Polyspace.

生成コードに MATLAB コードをコメントとして含める

MATLAB Function ブロックに対して生成されたコードと MATLAB® ソース コードとの相互関連付け。


Identifier Format Control

You can customize generated identifiers by specifying the Identifier format control parameters on the Code Generation > Identifiers pane in the Configuration Parameters dialog box. For each parameter, you can enter a macro that specifies whether, and in what order, certain text is included within generated identifiers. For example, you can specify that the root model name be inserted into each identifier using the $R token.


[識別子の最大の長さ] パラメーターを使用して、関数、型定義および変数名の文字数を制限する。



Customize Generated Identifier Naming Rules

Customize the naming of identifiers in the generated code.



Control Name Mangling in Generated Identifiers

Specify the position and length of name-mangling text in generated identifiers.

Specify Boolean and Data Type Limit Identifiers

Integrate the generated code with your code by specifying the identifiers that correspond to Boolean false and true. Also, specify the identifiers that correspond to data type limits, which the generated code uses to determine overflows.


コード ジェネレーターを使用して C または C++ コードを生成する場合、モデルには内部使用のために予約されているキーワードが含まれていてはなりません。

Maintain Traceability for Generated Identifiers

To verify your model, you can trace back and forth between generated identifiers and corresponding entities within the model. To maintain traceability, it is important that incremental revisions to a model have minimal impact on the identifier names that appear in generated code. There are two ways to minimally impact the identifier names:

Exceptions to Identifier Formatting Conventions

There are some exceptions to identifier formatting conventions for type names, non-Auto storage classes, and shared utilities.

Identifier Format Control Parameters Limitations

There are some limitations pertaining to how autogenerated identifiers comply with the setting of the Maximum identifier length parameter.

コード スタイル

Enhance Readability of Code for Flow Charts

Describes how to convert if-elseif-else code to switch-case statements to enhance readability of generated code.

Enhance Code Readability for MATLAB Function Blocks

Convert if-elseif-else code to switch-case statements.

Improve Data Coherency in Generated Code

Generate a single unique variable for each Data Store read and write operation and thereby enhance Data Coherency.

Control Parentheses in Generated Code

Specify how parentheses are placed in the code.

Optimize Code by Reordering Commutable Operands

Reorder the execution of operands in the generated code to improve efficiency.

到達不能な Stateflow switch ステートメントの default ケースの生成を抑制

switch-case ステートメントについて default ケースを生成するかどうかを指定する。

Replace Multiplication by Powers of Two with Signed Bitwise Shifts

Specify whether to replaces multiplication by powers of two with signed bitwise shifts.

Generate Code Containing Right Shifts on Signed Integers

Specify whether the generated code contains right shifts on signed integers.

Control Cast Expressions in Generated Code

Control the data type casts that the code generator specifies in the generated code.

コード テンプレート


カスタム ファイル処理 (CFP) ツールで生成コードの編成と形式をカスタマイズできます。

Code Generation Template (CGT) Files

Code Generation Template (CGT) files define the top-level organization and formatting of generated source code and header files. CGT files have the following applications:

Custom File Processing (CFP) Templates

A custom file processing (CFP) template imposes a simple structure on the code generation process.

Specify Templates For Code Generation

Create CGT files and CFP templates to use custom file processing features.

Generate Custom File and Function Banners

Using code generation template (CGT) files, you can specify custom file banners and function banners for the generated code files. File banners are comment sections in the header and trailer sections of a generated file. Function banners are comment sections for each function in the generated code. Use these banners to add a company copyright statement, specify a special version symbol for your configuration management system, remove time stamps, and for many other purposes. These banners can contain characters, which propagate to the generated code.

Change the Organization of a Generated File

Use data and code templates to change the organization of generated files.

Customize Generated File Names

Customize generated file names by using file naming rules.

Generate Source and Header Files with a Custom File Processing (CFP) Template

This example shows you the process of generating a simple source (.c or .cpp) and header (.h) file using the example CFP template. Then, it examines the template and the code generated by the template.

Comparison of a Template and Its Generated File

You can use a template to define what code the code generator adds to the generated file, control the location of code in the file, and optionally insert comments in the generated file.

Code Template API Summary

The code template API includes functions to obtain the names of the standard model files and other model-related information.

Template Symbols and Rules

This topic describes template symbols and rules for using them.