0
したがって、精度(double、quadなど)を定義できるように、任意の型の変数を大量に宣言する数学的なコードがあります。これを行うには、私は、ヘッダファイル#defineを使用して変数の型を設定する
input.hが GCC testEquations.c -oテストでコンパイル
#include<math.h>
#include<stdio.h>
#define PRECISION double
int main(){
return 0;
}
などのメインファイルに含まれて
PRECISION detg;
detg = 1.0+2;
input.hを持っています
コンパイルに失敗し、エラーが返されます。
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が二重に置き換えられないのですか?なぜこのエラーが出るのですか?
あなたは 'input.h'をどこに入れていますか? –
注意: '#define'ではなく、' typedef'を変数の型に使う方が良いでしょう。 – AntonH
はい、これはtypedefの仕事のように聞こえます – brianxautumn