简体   繁体   中英

Vector return from a function

I'm trying to give an array as a pointer to a function as I want to return an array from it. The problem comes when calling to the function. I have the following code:

void function(unsigned char p[4][4], unsigned char x, unsigned char* arr[4]) {
    unsigned char result;
    for (int ii=0;ii<4;ii++)
    {
        result= p[ii][1] - p[ii][2] + p[ii][0]*x + p[ii][3]*4;
        *arr[ii]=result;
    }
unsigned char function2(unsigned char p[4][4], unsigned char x, unsigned char y) {
    unsigned char arr[4];

    function(p, y, arr);
    ret= function3(arr, x);
    return ret;
}

The objective is to modify the value of the vector arr in function , in order to use it in function3 , that has nothing to do with function . The compilator is saying that:

cannot convert 'unsigned char*' to 'unsigned char**' for argument '3' to 'void function(unsigned char (*)[4], unsigned char, unsigned char**)

Any help is appreciated!

I think you can simple pass array as pointer (without pointer to array):

void function(unsigned char p[4][4], unsigned char x, unsigned char * arr) {
    unsigned char result;
    for (int ii = 0; ii < 4; ii++)
    {
        result = p[ii][1] - p[ii][2] + p[ii][0] * x + p[ii][3] * 4;
        arr[ii] = result;
    }
}

I think it is easiest way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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