The difference between double ** and double (*) [2] in C

What is the difference between double ** and double (*) [2].

If I understand well, double ** is a pointer to a double pointer, so it can be a 2D array of any size, whereas double (*) [2] is a pointer to a double [2] array.

So, if this is correct, how can you successfully pass the function.

For example, in:

void pcmTocomplex(short *data, double *outm[2]) 

if I pass double (*) [2] as a parameter, I have the following warning:

 warning: passing argument 2 of 'pcmTocomplex' from incompatible pointer type note: expected 'double **' but argument is of type 'double (*)[2]' 

What is the correct way to pass a double function (*) [2] to a function?

EDIT: Call Code

 fftw_complex *in; /* typedef on double[2] */ in = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * 1024); pcmTocomplex(data, in); 
+4
source share
3 answers
 void pcmTocomplex(short *data, double *outm[2]) 

This second parameter that you saw in this function prototype is an array of double pointers, not what you want.

 void pcmTocomplex(short *data, double (*outm)[2]) 

What it should look like if you want what you expect.

+1
source

double *outm[2] does not match double (*outm)[2] . The first is an array of pointers (and in this context is equivalent to double ** ); the second is a pointer to an array.

If in doubt, use cdecl .

+3
source

You need to change the second type of parameter:

 void pcmTocomplex(short *data, double (*outm)[2]) 

Note that the second parameter is changed to double (*outm)[2] .

Also note that in your code double *outm[2] in the parameter is exactly the same as double **outm .

+2
source

Source: https://habr.com/ru/post/1400562/


All Articles