我正在尝试在 matlab simulink 中创建一个 s-function block 。这是 mdlOutput 函数。当我在内部定义局部变量时,它给我一个错误
//////
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T *y = ssGetOutputPortRealSignal(S,0);// no error
real_T *x = ssGetContStates(S);//no error
UNUSED_ARG(tid);
real_T *a;// error:missing ';' before 'type'
real_T *b=5.0//error: illegal use of this type as an expression
}
不仅仅是real_T,除了模板中已经定义的y和x之外,我无法在函数内定义任何类型的局部变量。在顶部使用静态变量工作正常。普通变量可能有什么问题?
最佳答案
我明白了。我必须在 UNUSED_ARG(tid) 命令之前定义变量
关于c - c s-function 中局部函数内的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11857574/