2012-03-22 31 views
0

蔭C編寫代碼,其中結構被引用傳遞,在另一個函數不是指針,無法解引用

以下是用於被調用的函數聲明:

float Compute(float input, struct constraints* limits_record, struct constraints* state_record); 

凡limits_record和state_records兩者結構聲明如下:

struct constraints 
    { 
     float lower_limit; 
     float upper_limit; 
    }; 

上述功能正在從另一個功能(而不是從主)如下稱爲:

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) ; 
    } 

在編譯上面的代碼給錯誤「不是指針,不能順從」就行了

tmp_intgr = coefficient * (input + state_record->lower_limit) + state_record->upper_limit; 

可有人請幫我這個...

在此先感謝

+3

至於神祕的語法錯誤一般建議:分裂線或表達成小塊,直到你明白錯誤。 – 2012-03-22 05:43:11

+7

問題出在您未向我們顯示的某些代碼中。我複製並粘貼你的代碼並將其編譯到我的系統上;一旦我添加了「係數」的聲明,它就會無誤地編譯。向我們展示一個代表問題的完整自包含源文件。 – 2012-03-22 05:46:02

+1

你發佈的內容絕對沒有錯 - 它對我來說看起來不錯,它在MSVC下編譯得很好。拿Lars Wirzenius - 把表情分解成更小的部分,直到你明白錯誤。 – paulsm4 2012-03-22 05:52:36

回答

2

查找東西在你的代碼,如:

#define coefficient 

並將其更改爲:

#define coefficient .42