简体   繁体   English

C 指向 function 的指针

[英]C pointer to function with cast

I have a this function which needs a Two Dimensional Integer Array:我有一个需要二维 Integer 数组的 function :

void Add_Binary_To_Matrix(int (*qrMatrix)[21], int *binPtr,
        int x, int y, int count, int skipper, int direction)

And this array which is a one dimensional pointer array but I add memory to each row (which also makes it a two dimensional integer array right?):这个数组是一维指针数组,但我将 memory 添加到每一行(这也使它成为二维 integer 数组,对吗?):

int *qrCopy[currentVersion->height];
for (int i = 0; i < currentVersion->height; i++) 
    qrCopy[i] = malloc(currentVersion->height * sizeof(int));

So I've tried passing it a bunch of ways but none of them work:所以我尝试了很多方法,但它们都不起作用:

Add_Binary_To_Matrix((int *)qrCopy, binPtr, 20, 20, 0, 0, 1);
Add_Binary_To_Matrix(qrCopy, binPtr, 20, 20, 0, 0, 1);
Add_Binary_To_Matrix(&((int *)qrCopy[0]), binPtr, 20, 20, 0, 0, 1);

but passing it like that doesn't seem to work so my question is how can I pass this array to the function?但是像这样传递它似乎不起作用所以我的问题是如何将这个数组传递给 function?

It is impossible to pass the array to the function.无法将数组传递给 function。

The type of int (*qrMatrix)[21] is a pointer to "21-element array of integers". int (*qrMatrix)[21]的类型是指向“21 元素整数数组”的指针。

qrCopy is an array of pointers, so this cannnot be passed. qrCopy是一个指针数组,因此无法传递。

How to set the argument: Create an array and obtain pointer to that.如何设置参数:创建一个数组并获取指向它的指针。

int array[21];
Add_Binary_To_Matrix(&array, binPtr, 20, 20, 0, 0, 1);

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

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