coder.cstructname
在生成的代码中命名C结构类型
coder.cstructname
为MATLAB使用的生成或外部定义的C结构类型命名®在生成的代码中表示为结构的变量。
语法
structName coder.cstructname (var)
structName coder.cstructname (var,“外来的”,“HeaderFile”,HeaderFile)
structName coder.cstructname (var,“外来的”,“HeaderFile”,HeaderFile,对齐,对齐)
outtype = code .cstructname(intype,structName)
outtype = code .cstructname(intype,structName,'extern','HeaderFile', HeaderFile)
outtype = code .cstructname(inptype,structName,'extern','HeaderFile', HeaderFile,' align ',align)
描述
coder.cstructname (
为MATLAB变量生成的C结构类型命名var
,structName
)var
.输入var
可以是结构或单元格数组。在用于生成代码的函数中使用此语法。的地方coder.cstructname
在定义之后var
并且在第一次使用之前var
.如果var
入口点(顶级)函数输入参数是placecoder.cstructname
在函数的开头,在任何控制流语句之前。
coder.cstructname (
指定要用于的C结构类型var
,structName
“外来的”,“HeaderFile”,headerfile
)var
有名字structName
并且在外部文件中定义,headerfileName
.
可以使用“外来的”
选项,而不指定头文件。但是,最好的做法是指定头文件,以便代码生成器生成# include
语句放在正确的位置。
coder.cstructname (
还指定外部定义的结构类型的运行时内存对齐方式var
,structName
“外来的”,“HeaderFile”,headerfile
“对齐”,对齐
)structName
.如果你有嵌入式编码器®并使用自定义代码替换库(CRL),指定对齐方式,以便代码生成器能够匹配需要对结构进行对齐的CRL函数。看到代码替换的数据对齐(嵌入式编码)。
返回结构或单元格数组类型对象outtype
= coder.cstructname (intype
,structName
)outtype
指定要生成的C结构类型的名称。coder.cstructname
创建outtype
使用输入类型的属性intype
.然后,它设置TypeName
财产structName
.类使用的类型对象可使用此语法创建codegen
arg游戏
选择。不能在用于生成代码的函数中使用此语法。
类型中不能使用此语法MATLAB函数块。
返回类型对象outtype
= coder.cstructname (intype
,structName
“外来的”,“HeaderFile”,headerfile
)outtype
指定外部定义的C结构类型的名称和位置。代码生成器对具有type的变量使用外部定义的结构类型outtype
.
类型中不能使用此语法MATLAB函数块。
创建类型对象outtype
= coder.cstructname (inptype
,structName
“外来的”,“HeaderFile”,headerfile
“对齐”,对齐
)outtype
它还指定了C结构类型的对齐方式。
类型中不能使用此语法MATLAB函数块。
例子
输入参数
限制
你不能申请
coder.cstructname
直接到全局变量。若要命名要与全局变量一起使用的结构类型,请使用coder.cstructname
创建命名结构类型的类型对象。然后,当你跑步的时候codegen
,指定全局变量具有该类型。看到将C结构类型命名为全局结构变量(MATLAB编码器)。对于单元格数组输入,外部定义的结构的字段名必须为
f1
,f2
等等。
提示
有关代码生成器如何确定结构字段的C/ c++类型的信息,请参见将MATLAB类型映射到生成代码中的类型(MATLAB编码器)。
使用
coder.cstructname
在结构上,数组设置基元素的结构类型的名称,而不是数组的名称。因此,您不能申请coder.cstructname
,然后将其应用于具有不同C结构类型名称的数组。例如,以下代码是不允许的。第二个coder.cstructname
尝试将基类型的名称设置为myStructArrayName
,与前面指定的名称冲突,myStructName
.用字段a定义标量结构myStruct = struct(“一个”, 0);coder.cstructname (myStruct“myStructName”);用字段a定义结构数组myStructArray = repmat(myStruct,k,n);coder.cstructname (myStructArray“myStructArrayName”);
应用
coder.cstructname
对结构数组的元素产生与应用相同的结果coder.cstructname
到整个结构数组。如果你申请coder.cstructname
对于结构数组的元素,必须使用单个下标引用该元素。例如,你可以使用var (1)
,但不是var (1, 1)
.应用coder.cstructname
来var (:)
产生与应用相同的结果coder.cstructname
来var
或var (n)
.异构单元格数组在生成的代码中表示为结构。以下是使用时的注意事项
coder.cstructname
使用单元格数组:在生成代码的函数中,使用
coder.cstructname
使用单元格数组变量将使单元格数组异构。因此,如果单元格数组是一个入口点函数输入,并且它的类型是永久同构的,那么就不能使用coder.cstructname
用单元格数组。使用
coder.cstructname
一个齐次的编码器。CellType
对象intype
使返回的对象异构。因此,您不能使用coder.cstructname
是永久齐次的编码器。CellType
对象。有关单元格数组何时是永久同构的信息,请参见在命令行中指定单元格数组输入(MATLAB编码器)。当与
编码器。CellType
对象,coder.cstructname
创建一个编码器。CellType
永久异构的对象。
这些建议只适用于MATLAB函数块:
MATLAB函数块输入和输出结构与总线信号相关联。为结构类型生成的名称来自总线信号名称。不要使用
coder.cstructname
为输入或输出信号命名结构类型。看到在MATLAB函数块中创建结构.代码生成器根据标识符命名规则生成结构类型名称,即使将结构类型命名为
coder.cstructname
.如果您有Embedded Coder,您可以自定义命名规则。看到生成标识符的构造(嵌入式编码)。