C 使用参数调用函数会出现两个错误
我收到的错误:C 使用参数调用函数会出现两个错误,c,variables,C,Variables,我收到的错误: main.c:63:7: error: conflicting types for 'integrieren' main.c:39:6: note: previous implicit declaration of 'integrieren' was here 主要条款c:39: A = integrieren(dx,y); 与 主要条款c:63: float integrieren(float dx,float y[1001]) 在第39行,当您使用int
main.c:63:7: error: conflicting types for 'integrieren'
main.c:39:6: note: previous implicit declaration of 'integrieren' was here
主要条款c:39:
A = integrieren(dx,y);
与
主要条款c:63:
float integrieren(float dx,float y[1001])
在第39行,当您使用integieren()时,没有先将其原型化,编译器假定其返回类型,并且所有参数都是整数
要么将integier()的定义移到调用它的位置上方,要么先将其原型化。在尝试在
main.c:39使用它之前,您可能没有删除float integrieren(float dx,float y y[1001])
默认的c
行为是在这种情况下隐式声明函数,但是它假定的类型是int
。因此,您在main.c:39处得到一个inmplicit声明,在第63行得到一个显式声明,并返回错误。我认为这是ansi-c的行为,较新版本的标准在调用未定义函数时会将其称为错误,您会得到“未定义符号整数”
”或类似的错误(尽管99%确定)
只需向前声明float integrieren(float dx,float y[1001])代码>在main.c
中第39行上方,它可能也应该位于全局范围内
差不多
#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
}
#包括
#包括
浮点整数(浮点dx,浮点y[1001])//宣言
int main(){
//主要材料
返回0;
}
//定义
浮点整数(浮点dx,浮点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
}