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

感情迁移 提交于 2019-12-21 17:30:06

问题


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);

回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/9633110/difference-between-double-and-double-2-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!