使用参数调用函数会出现两个错误

标签 c variables

我收到的错误:

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/

相关文章:

c - 简单读取/显示 C 程序在用户输入数据时输出不正确的值

C - 在结构内部的指针上使用 Realloc 时崩溃

c - 可以在 C 中为特定结构编写函数吗?

c++ - 使用相同的参数名称和成员名称是否有效

variables - 在 zsh 中使用变量作为命令参数

C scanf 意外地使用 %i 扫描日期

c - GCC + 内联汇编 - notl 上的意外段错误

javascript - 调用函数时变量不改变

javascript - 是否可以在引用索引的循环中调用 jQuery 中的变量

java - 如何结合 AngularJS 和 Thymeleaf 模板