结构体
结构体的代码生成
MATLAB® Coder™ 支持为结构体生成代码,但对于操作、标量结构体的值属性和结构体数组存在一些限制。您可以为标量结构体和结构体数组生成代码。请遵守对子结构体和字段进行索引和赋值的限制。在生成的代码中,结构体参量按引用或按值传递。
函数
coder.cstructname | 在生成代码中命名 C 结构体类型 |
主题
- Structure Limitations for Code Generation
Adhere to code generation restrictions for structures.
- 为结构体数组生成代码
此示例说明如何编写使用结构体数组的 MATLAB 函数,以便于进行代码生成。
- 在生成的代码中按引用或按值传递结构体参量
控制结构体参量是按引用传递还是按值传递。
- Name C Structure Type to Use with Global Structure Variable
Use
coder.cstructnameto define a type object for a global structure. - Synchronize MATLAB Structure with Structure Type in Generated Code
Use a constructor function and
coder.OutputTypeto generate a structure type that you can use in MATLAB functions and the generated code.
疑难解答
对变量在使用前未定义导致的代码生成错误进行故障排除。