C 不是指针,无法取消引用
我在用C编写代码,其中结构通过引用传递,并在另一个函数中使用 以下是被调用的函数声明:C 不是指针,无法取消引用,c,pointers,C,Pointers,我在用C编写代码,其中结构通过引用传递,并在另一个函数中使用 以下是被调用的函数声明: float Compute(float input, struct constraints* limits_record, struct constraints* state_record); 其中,限制记录和状态记录的结构声明如下: struct constraints { float lower_limit; float upper_limit;
float Compute(float input, struct constraints* limits_record, struct constraints* state_record);
其中,限制记录和状态记录的结构声明如下:
struct constraints
{
float lower_limit;
float upper_limit;
};
上述函数是从另一个函数(不是从main)调用的,如下所示:
autotrim_out=Compute(inp, &limit, &state);
有关计算函数的以下代码详细信息:
float Compute(float input, struct constraints* limits_record, struct constraints* state_record)
{
float tmp_lim;
float tmp_intgr;
tmp_intgr = coefficient * (input + state_record->lower_limit) + state_record->upper_limit;
if (tmp_intgr < limits_record->lower_limit)
tmp_lim = limits_record->lower_limit ;
else if(tmp_intgr > limits_record->upper_limit)
tmp_lim = limits_record->upper_limit;
else
tmp_lim = tmp_intgr;
state_record->upper_limit = tmp_lim;
state_record->lower_limit = input ;
return(tmp_lim) ;
}
有人能帮我解决这个问题吗
提前感谢在您的代码中查找以下内容:
#define coefficient
并将其更改为:
#define coefficient .42
对于神秘的语法错误的一般建议是:将行或表达式拆分为较小的部分,直到您理解错误。问题在于您没有向我们展示的某些代码。我复制并粘贴了你的代码,并在我的系统上编译了它;一旦我为
系数
添加了一个声明,它的编译就没有错误。向我们展示一个完整的、自包含的源文件,它代表了这个问题。你所发布的内容绝对没有问题——在我看来还可以,并且在MSVC下编译得很好。以Lars Wirzenius为例,将表达式分成小块,直到您理解错误为止
#define coefficient .42