【发布时间】:2015-01-20 08:33:59
【问题描述】:
我正在尝试为 Simulink 中的 C 函数提供结构。到目前为止我的步骤:
-
在配置参数自定义代码中包含
.h和.c。我的标题有一个结构定义:typedef struct mystruct { int m; int *i; double *x;}mystruct -
现在在我的 Simulink 下的 MATLAB 函数中:
function y = fcn(u)%#codegen m=int32(1); i=zeros(10,1,'int32'); x=zeros(10,1); s.m=m; s.i=i; s.x=x; coder.cstructname(s,'mystruct','extern'); D=int32(0); D=coder.ceval('accesmystruct',coder.ref(s)); y=10;
如果我运行代码,我会从代码生成中得到一个长错误,表明它不能在 c 代码中编译。错误是:
c2_Test2.c
c2_Test2.c(57) : error C2143: syntax error : missing ')' before '*'
c2_Test2.c(57) : error C2081: 'cs_size' : name in formal parameter list illegal
c2_Test2.c(57) : error C2143: syntax error : missing '{' before '*'
c2_Test2.c(57) : error C2059: syntax error : ')'
c2_Test2.c(60) : error C2143: syntax error : missing ')' before '*'
....
仅当我将两个变量 i 和 x 声明为指针时才会发生这种情况。如果我在标头和 MATLAB 函数中将它们声明为标量,它就可以工作。
有人看到我做错了吗?
【问题讨论】:
标签: c matlab simulink matlab-coder