我收到的错误:
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])
最佳答案
在尝试在 main.c:39
中使用它之前,您可能没有 delcare float integrieren(float dx,float y[1001])
。
默认的c
行为是在这种情况下隐式声明函数,但它假定的类型是int
。因此,您会在 main.c:39
处得到一个隐式声明,并在第 63 行得到一个显式声明,并产生错误。我认为这是 ansi-c 行为,较新版本的标准会在调用未定义函数时将其称为错误,并且您会得到“ undefined symbol 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
调用签名是什么。您不需要在那里定义主体,只需声明它即可。
关于使用参数调用函数会出现两个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21190769/