简体   繁体   English

C中双**和双(*)[2]之间的差异

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

What is the difference between a double ** and a double (*)[2]. 双**和双(*)[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]. 如果我理解的话,double **是指向double的指针,因此它可以是任何大小的2D数组,而double(*)[2]是指向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 : 如果我传递一个double(*)[2]作为参数,我有以下警告:

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 ? 将double(*)[2]传递给函数的正确方法是什么?

EDIT : calling code 编辑:调用代码

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

pcmTocomplex(data, in);

double *outm[2] is not the same as double (*outm)[2] . double *outm[2]double (*outm)[2] The first is an array of pointers (and is equivalent to double ** in this context); 第一个是指针数组(在此上下文中相当于double ** ); the second is a pointer to an array. 第二个是指向数组的指针。

If in doubt, use cdecl . 如有疑问,请使用cdecl

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] . 注意第二个参数改为double (*outm)[2]

Also note that in your code, double *outm[2] in the parameter is exactly same as double **outm . 另请注意,在您的代码中,参数中的double *outm[2]double **outm 完全相同

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. 这个如果你想要它应该是什么样子,你期望什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM