Difference between double ** and double (*)[2] in

2019-04-09 15:56发布

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

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

So if it is right, how can it be passed successfully to a function.

For instance in :

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

if I pass a 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 right way to pass a double (*)[2] to a function ?

EDIT : calling code

fftw_complex        *in;             /* typedef on double[2] */
in = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * 1024);

pcmTocomplex(data, in);

3条回答
Bombasti
2楼-- · 2019-04-09 16:06

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

If in doubt, use cdecl.

查看更多
Emotional °昔
3楼-- · 2019-04-09 16:18

You need to change second parameter type to this:

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

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

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

查看更多
我只想做你的唯一
4楼-- · 2019-04-09 16:24
void pcmTocomplex(short *data, double *outm[2])

This second parameter , you seen in this function prototype imply array of double pointers and not actually what you want.

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

This how it should look like if you want , what you expect.

查看更多
登录 后发表回答