c - 两个 double 怎么会是相互冲突的类型呢?

标签 c

#include<stdio.h>
#include<math.h>


int main(void){
  double a=0,r=0,n=0;
  printf("Enter Constant a:");
  scanf("%lf",&a);
  printf("Enter Constant r:");
  scanf("%lf",&r);
  printf("Enter Variable n:");
  scanf("%lf",&n);

  double an;
  an = geom_rec(a,r,n);    // Line 15

  return 0;
}

double geom_rec(double a,double r,double n){    // Line 20
  double ans=a;
  return a;
}

错误:

Line 20: error: conflicting types for 'geom_rec'
Line 15: error: previous implicit declaration of 'geom_rec' was here

最佳答案

您忘记为函数创建原型(prototype)。

将以下内容放在 main 函数之前(您也可以将整个函数移到 main 之上):

double geom_rec(double a,double r,double n);

如果您调用之前未定义或原型(prototype)化的函数,编译器会假定它返回 int - 这与您的实际返回类型冲突。

关于c - 两个 double 怎么会是相互冲突的类型呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212378/

相关文章:

c++ - 定点处理器中浮点运算的数据结构

CAPL 如何使用 memcpy 用零初始化数组

C结构字符串错误

函数调用后无法定义变量

c - 在 c 用户输入中编译错误

c - 使用不同的结构对齐设置

c - Valgrind 在 Mac OSX 10.8 上的空程序上显示内存泄漏

c - Linux 上的系统调用参数类型是什么?

c - 为什么 "stack smashing detected"不是刷完马上出现?

c - EVP_UPDATE 永远不会返回