Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: passing argument ’from incompatible pointer type [enabled by default]'

Tags:

c

pointers

fft

I've been looking around on the other threads somehow related to this, but somehow I just don't get it...

I want to do some FFT on a set of values I have evaluated and wrote this program to first read the values and save them to an array of size 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);
}

In the same file I also do the FFT with the help of this program:

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

However, when I compile I always get this error:

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

Since this is my first time programming, I really don't know what is wrong with my code. Will I have to set more flags for the compiler or stuff like that (because I had to do this -lm stuff or it wouldn't compile and said something like pow not found or so)?

Also I was made aware that there might be a difference when writing on a Windows or a Linux machine, and I am using Linux, Lubuntu 12.10 32-bit if it's a problem of the OS.

like image 837
mitit100 Avatar asked Dec 28 '12 18:12

mitit100


2 Answers

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

Drop ampersands from that line.


The problem is that the & operator in this context produces an expression with a different type than what FFT expects. FFT expects a pointer to a double and &werte produces a pointer to an array of N elements. So, in order to make FFT happy, just pass werte which will quietly decay to a pointer to the first element.

For more information on pointers to arrays, there's a C FAQ.

like image 54
cnicutar Avatar answered Nov 20 '22 09:11

cnicutar


werte[] and nul[] are arrays, but the word werte itself is an address of the first element of the array. So when you do &werte you're trying to pass an address of the address (as @cnicutar pointed out, this should actually read pointer to an array of N elements). SO just pass werte and nul without the ampersand signs to pass the address of these arrays.

like image 7
varevarao Avatar answered Nov 20 '22 07:11

varevarao