我一直在寻找与此有关的其他线程,但不知怎的,我只是不明白...
我想对我评估的一组值进行一些FFT,并编写该程序以首先读取值并将它们保存到一个大小的数组中n.
int main () {
// some variables and also a bit of code to read the 'messwerte.txt'
printf("Geben sie an wieviele Messwerte ausgelesen werden sollen: ");
scanf("%d", &n);
double werte[n]; //Array der "fertigen" Messwerte
in = fopen ("messwerte.txt","r");
double nul[n]; //Array von nullen
int logN = 14;
l=FFT(logN,&werte,&nul);
}
Run Code Online (Sandbox Code Playgroud)
在同一个文件中,我也在这个程序的帮助下进行FFT:
double FFT (int logN, double *real, double *im) //logN is base 2 log(N) {
// blabla FFT calculation
}
Run Code Online (Sandbox Code Playgroud)
但是,当我编译时,我总是得到这个错误:
gcc FFT.c -lm
FFT.c: In function ‘main’:
FFT.c:94:2: warning: passing argument 2 of ‘FFT’ from incompatible pointer type [enabled by default]
FFT.c:4:8: note: expected ‘double *’ but argument is of type ‘double (*)[(unsigned int)(n)]’
FFT.c:94:2: warning: passing argument 3 of ‘FFT’ from incompatible pointer type [enabled by default]
FFT.c:4:8: note: expected ‘double *’ but argument is of type ‘double (*)[(unsigned int)(n)]’
Run Code Online (Sandbox Code Playgroud)
由于这是我第一次编程,我真的不知道我的代码有什么问题.我是否必须为编译器设置更多的标志或类似的东西(因为我必须做这些-lm东西或它不会编译并说像找不到的东西等)?
此外,我还意识到在Windows或Linux机器上编写时可能会有所不同,而且我使用的是Linux,Lubuntu 12.10 32位,如果它是操作系统的问题.
cni*_*tar 11
Run Code Online (Sandbox Code Playgroud)l=FFT(logN,&werte,&nul); ^ ^
从该线上掉落&符号.
问题是&此上下文中的运算符生成的表达式与FFT预期的类型不同.FFT需要一个指向double的指针,并&werte产生一个指向N个元素数组的指针.所以,为了使FFT快乐,只是传递werte将悄然衰变到指向第一个元素的指针.
有关指向数组的指针的更多信息,有一个C FAQ.
werte[]并且nul[]是数组,但单词werte本身是数组的第一个元素的地址.因此,当你&werte尝试传递地址的地址时(正如@cnicutar指出的那样,这实际上应该读取指向N个元素数组的指针).所以只是通过werte并且nul没有符号标志来传递这些数组的地址.