2014-01-17 65 views
0

錯誤我收到:帶參數調用函數給出了兩個錯誤

main.c:63:7: error: conflicting types for 'integrieren' 
main.c:39:6: note: previous implicit declaration of 'integrieren' was here 

MAIN.C:39:

 A = integrieren(dx,y); 

float A,x[1001],y[1001],dx; 

的main.c:63:

float integrieren(float dx,float y[1001]) 
+0

請注意,這是一個錯誤和一個筆記,你應該看看哪裏,而不是兩個錯誤。 – luk32

回答

0

在使用integieren()而沒有先初始化它的情況下,在第39行,編譯器假定它的返回類型,所有參數都是整數。

將integierer()的定義移動到被調用位置的上方,或者將其初始化爲原型。

1

在嘗試使用main.c:39之前,您可能沒有delcare float integrieren(float dx,float y[1001])

默認c行爲是暗示在這種情況下聲明函數,但它假定的類型是int。因此,您會在main.c:39處得到一個隱性聲明,並在第63行顯示一個,並顯示錯誤。我認爲這是ansi-c行爲,當調用未定義的函數時,新版本的標準會將其稱爲錯誤,並且您會得到「未定義符號integrieren」或類似的錯誤(儘管它99%確定)。

只要在main.c的第39行上面申報float integrieren(float dx,float y[1001]);也許它也應該位於全球範圍內。

喜歡的東西

#include<fancy_stuff.h> 
#include<fancier_stuff.h> 

float integrieren(float dx,float y[1001]); //declaration 

int main(){ 
    //main stuff 
    return 0; 
} 

//definition 
float integrieren(float dx,float y[1001]){ 
    //body 
} 

然後編譯器知道integrieren調用簽名是什麼。你不需要定義那裏的身體,只需聲明它。

相關問題