本页面提供的是上一版软件的文档。当前版本中已删除对应的英文页面。
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 循环
使用 For-Iterator Subsystem 模块、Stateflow 图或 MATLAB Function 模块在生成的代码中创建for
循环。 - 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. - Conditional Inclusions (#if / #endif)
Include preprocessor conditionals in your generated code by implementing variant blocks in your model.
结构体
- Structures of Parameters
Create a flat structure or nested structures that store parameter data in the generated code. - Structures of Signals
Create a flat structure that contains signal data in the generated code. - Nested Structures of Signals
Create a structure whose fields are also structures. - 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.