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
Use a Switch block, a Stateflow Chart, or MATLAB Function block to create anif-else
statement in the generated code. - Switch
Use a Switch Case block or MATLAB Function block to create answitch
statement in the generated code. - For Loop
Use a For-Iterator Subsystem block, Stateflow Chart, or MATLAB Function block to create afor
loop in the generated code. - While Loop
Use a White Iterator Subsystem block, Stateflow Chart, or MATLAB Function block to create awhile
loop in the generated code. - Do While Loop
Use a While Iterator Subsystem block or Stateflow Chart to create ado while
loop in the generated code.
関数
- Function Call
To generate a function call, add a subsystem, which implements the operations that you want. - 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.
プリプロセッサ命令
- Macro Definitions (#define)
Generate parameter data as a constant-valued macro. - 条件付きインクルード (#if / #endif)
モデルにバリアント ブロックを実装して生成コードにプリプロセッサの条件を含める。
構造体
- パラメーターの構造体
パラメーター データを格納するフラットな構造体または入れ子にされた構造体を生成コード内に作成する。 - 信号の構造体
信号データを格納するフラットな構造体を生成コード内に作成する。 - 信号の入れ子にされた構造体
フィールドも構造体である構造体を作成する。 - Bitfields
Store Boolean data in bitfields in the generated code.
配列
- 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.
ポインター
- Pointers
Generate code that accesses data from your handwritten code through a pointer.