我有定義的以下結構 - 座標的一個結構本身是一個父結構的成員編譯器警告傳遞陣列(本身結構的部件)到功能
typedef struct _coord {
double x; // time axis - seconds rather than samples
double y;
} t_coord;
typedef struct _algosc {
t_coord coords[COORD_COUNT];
//... struct continues beyond this but...
} t_algosc;
創建一個指針父結構然後分配內存。 object_alloc是特定於其他地方定義的API(MAX5)的malloc類型函數。這是所有工作,所以我不包括細節。
static t_class *algosc_class; // pointer to the class of this object
t_algosc *x = object_alloc(algosc_class)
這是該函數的聲明,而我希望傳遞座標結構的陣列
void au_update_coords(t_coord (*coord)[])
餘數組傳遞給該函數如下,
au_update_coords(x->coords);
它一切正常,但我得到編譯器警告
1>db.algosc~.c(363): warning C4047: 'function' : 't_coord (*)[]' differs in levels of indirection from 't_coord [4]'
1>db.algosc~.c(363): warning C4024: 'au_update_coords' : different types for formal and actual parameter 1
我無法解決傳遞結構的正確方法。任何人都可以幫忙也只是爲了我的薰陶,我會冒什麼樣的風險讓它保持原樣?
您的示例聲明需要七個參數,但您只需使用一個參數調用該函數。我認爲這是通過不完整的傳遞來爲您的問題刪除不必要的代碼?請糾正它。 – ruakh
數組自然衰減到指針,所以不需要傳遞指向數組的指針,只需傳遞數組本身(現在就是這樣),這當然必須在函數參數聲明中反映出來(即放棄指針聲明)。 –
謝謝ruakh - 現在正在更正。 – DanBennett