[英]Method signature in C, passing pointer on static array
I have the following arrays: 我有以下数组:
char* mask[9];
int hSobelMask[9] = {
-1, -2, -1,
0, 0, 0,
1, 2, 1};
I want to give a pointer on this array to a method like this: 我想在这个数组上提供一个指向这样的方法的指针:
int H = applyMask(&mask, &hSobelMask);
The signature of the applyMask function is the folowing: applyMask函数的签名如下:
int applyMask(char** mask[9], int* sobelMask[9]);
But I get the following compile warning: 但是我得到以下编译警告:
demo.c: In function ‘customSobel’:
demo.c:232:7: warning: passing argument 1 of ‘applyMask’ from incompatible pointer type
demo.c:181:5: note: expected ‘char ***’ but argument is of type ‘char * (*)[9]’
demo.c:232:7: warning: passing argument 2 of ‘applyMask’ from incompatible pointer type
demo.c:181:5: note: expected ‘int **’ but argument is of type ‘int (*)[9]’
What does this warning mean, how do I get rid of it ? 此警告是什么意思,我该如何消除它?
You want to pass the pointers to these arrays? 您想将指针传递给这些数组吗? So you're probably looking for this:
因此,您可能正在寻找:
int applyMask(char* (*mask)[9], int (*sobelMask)[9]);
A char * ___[9]
is an array of char *
, and a char * * ___[9]
is an array of char * *
. char * ___[9]
是char *
的数组,而char * * ___[9]
是char * *
的数组。 They're not compatible. 它们不兼容。 Just change your function signature to this:
只需将函数签名更改为此:
int applyMask(char** mask, int* sobelMask)
or this: 或这个:
int applyMask(char* mask[], int sobelMask[])
Edited to add (after Shahbaz's comment below): Call your function like this: 编辑添加 (在下面Shahbaz的评论之后):像这样调用函数:
int H = applyMask(mask, hSobelMask);
There's no need for those &
s, since an array variable already is a pointer to the contents of the array. 不需要那些
&
,因为数组变量已经是指向数组内容的指针。
int applyMask(char** mask, int* sobelMask);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.