警告:从不兼容的指针类型[默认启用]传递参数'

时间:2012-12-28 18:14:23

标签: c pointers fft

我一直在寻找与此有关的其他线程,但不知怎的,我只是不明白......

我想对我评估的一组值进行一些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);
}

在同一个文件中,我也借助这个程序进行FFT:

double FFT (int logN, double *real, double *im) //logN is base 2 log(N) {
// blabla FFT calculation
}

然而,当我编译时,我总是得到这个错误:

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)]’

由于这是我第一次编程,我真的不知道我的代码有什么问题。我是否必须为编译器设置更多的标志或类似的东西(因为我必须执行此-lm的东西,否则它将无法编译并且说像找不到电源的东西那么大?)

此外,我还意识到在Windows或Linux机器上书写时可能会有所不同,而且我使用Linux,Lubuntu 12.10 32位,如果它是操作系统的问题。

2 个答案:

答案 0 :(得分:11)

l=FFT(logN,&werte,&nul);
           ^      ^

从该行中删除&符号。


问题是此上下文中的&运算符生成的表达式与FFT期望的类型不同。 FFT期望指向double的指针,&werte生成指向N个元素数组的指针。因此,为了使FFT满意,只需传递werte,它将悄然衰变为指向第一个元素的指针。

有关指向数组的指针的更多信息,有一个C FAQ

答案 1 :(得分:7)

werte[]nul[]是数组,但单词werte本身是数组第一个元素的地址。所以,当你执行&werte时,你试图传递地址的地址(正如@cnicutar指出的那样,这应该实际上是读取指向N个元素数组的指针)。因此,只需通过wertenul而不使用&符号来传递这些数组的地址。

相关问题