このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
C コード構造のモデル化パターン
特定の C 構造を生成するモデル化パターンの適用
いくつかの標準的な方法を使用して、生成コード内で特定の C 構造体を生成するモデルを設定できます。ブロック、S-Function、Stateflow チャート、MATLAB Function ブロック、データ オブジェクトおよびカスタム ストレージ クラスを使用して、データ型、構造体、配列、制御フロー構造、関数、プリプロセッサ命令およびポインターなどの C 構造体を生成できます。開始するには、Prepare a Model for Code Generationを参照してください。業界標準、ガイドラインおよびブロックの使用法も参照してください。
トピック
タイプ、演算子、式
- Typedef
Create data type aliases by generatingtypedef
statements. - Definition, Initialization, and Declaration of Parameter Data
Control the file placement of the declaration, definition, and initialization of parameter data. - Definition and Declaration of Signal Data
Control the file placement of the declaration and definition of signal data. - Data Type Conversion
Create a data type conversion using a Data Type Conversion block, Stateflow Chart, or MATLAB Function block. - Type Qualifiers
Apply theconst
andvolatile
keywords to a global variable that represents parameter data. - Relational and Logical Operators
Implement relational and logical operators using Simulink blocks, Stateflow Charts, and MATLAB Function blocks. - Bitwise Operations
Perform bitwise operations using the Bitwise Operator block, a Stateflow Chart, or MATLAB Function block. - Enumeration
To generate an enumerated data type, define an enumeration class in a MATLAB file.
フロー制御
- if-else
Switch ブロック、Stateflow チャート、または MATLAB Function ブロックを使用して、生成コードでif-else
ステートメントを作成する。 - スイッチ
Switch Case ブロックまたは MATLAB Function ブロックを使用して、生成コードでswitch
ステートメントを作成する。 - for ループ
For Iterator Subsystem ブロック、Stateflow チャート、または MATLAB Function ブロックを使用して、生成コードでfor
ループを作成する。 - while ループ
While Iterator Subsystem ブロック、Stateflow チャート、または MATLAB Function ブロックを使用して、生成コードでwhile
ループを作成する。 - do while ループ
While Iterator Subsystem ブロックまたは Stateflow チャートを使用して、生成コードでdo while
ループを作成する。
関数
- 関数呼び出し
関数呼び出しを生成するために、目的の操作を実装するサブシステムを追加する。 - Function Prototyping
Create a function call using graphical functions or function prototype control. - External C Functions
Integrate legacy C functions in the generated code by either creating an S-function or making a call to an external C function.
プリプロセッサ命令
- マクロ定義 (#define)
パラメーター データを定数値のマクロとして生成する。 - 条件付きインクルード (#if / #endif)
モデルにバリアント ブロックを実装して生成コードにプリプロセッサの条件を含める。
構造体
- パラメーターの構造体
パラメーター データを格納するフラットな構造体または入れ子にされた構造体を生成コード内に作成する。 - 信号の構造体
信号データを格納するフラットな構造体を生成コード内に作成する。 - 信号の入れ子にされた構造体
フィールドも構造体である構造体を作成する。 - ビットフィールド
生成コードで boolean データをビットフィールドに格納する。
配列
- Arrays for Parameters
Create an array of parameter data in the generated code. - Arrays for Signals
Create an array of signal data in the generated code.
ポインター
- ポインター
手書きコードのデータにポインターを使用してアクセスするコードを生成する。