所以我有一个数学代码,它声明了大量具有任意类型的变量,因此可以定义它的精度(double,quad等)。为此,我有一个头文件
input.h
PRECISION detg;
detg = 1.0+2;
其中input.h包含在主文件中,如
#include<math.h>
#include<stdio.h>
#define PRECISION double
int main(){
return 0;
}
编译 gcc testEquations.c -o test
但编译失败并给出错误
In file included from testEquations.c:16:0:
./GHG_Files/input.h:3:1: warning: data definition has no type or storage class
detg = 1.0+2;
^
./GHG_Files/input.h:3:1: warning: type defaults to ‘int’ in declaration of ‘detg’ [-Wimplicit-int]
./GHG_Files/input.h:3:1: error: conflicting types for ‘detg’
./GHG_Files/input.h:1:11: note: previous declaration of ‘detg’ was here
PRECISION detg;
我的问题是,为什么PRECISION不会像您认为的那样被替换为double,为什么会出现此错误?
答案 0 :(得分:2)
您不能将detg = 1.0+2;
放在函数之外。写PRECISION detg = 1.0+2;
或将detg = 1.0+2;
放在主函数中。