0
所以我有一个数学代码,用一个任意类型声明一大堆变量,以便可以定义它的精度(双精度,四元等)。要做到这一点,我有一个头文件使用#define设置一个变量类型
input.h
PRECISION detg;
detg = 1.0+2;
凡input.h包括在像
#include<math.h>
#include<stdio.h>
#define PRECISION double
int main(){
return 0;
}
一个主文件与 的gcc -o testEquations.c编译测试
但编译失败并给出错误
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,为什么会出现此错误?
你在哪里包括'input.h'? –
备注:最好使用'typedef'来代替变量类型,而不是'#define'。 – AntonH
是的,这听起来像是一个typedef的工作 – brianxautumn