Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 重写指向输出参数的返回指针_Objective C_Function_Pointers - Fatal编程技术网

Objective c 重写指向输出参数的返回指针

Objective c 重写指向输出参数的返回指针,objective-c,function,pointers,Objective C,Function,Pointers,我正在玩openSSL库,它需要我复习指针,我遇到了困难 我有一个objective-c方法: -(unsigned char *)encryptTake1:(unsigned char *)input inputLength:(int)inLen outputLength:(int*)outLen; 它获取一些数据,对其进行加密,并返回指向该数据的指针和数据长度作为输出参数 我想对此进行更改,以便将加密数据也作为输出参数处理,并使用返回值指示成功或失败。这就是我所拥有的: -(int)enc

我正在玩openSSL库,它需要我复习指针,我遇到了困难

我有一个objective-c方法:

-(unsigned char *)encryptTake1:(unsigned char *)input inputLength:(int)inLen outputLength:(int*)outLen;
它获取一些数据,对其进行加密,并返回指向该数据的指针和数据长度作为输出参数

我想对此进行更改,以便将加密数据也作为输出参数处理,并使用返回值指示成功或失败。这就是我所拥有的:

-(int)encryptTake2:(unsigned char *)input inputLength:(int)inLen output:(unsigned char *)output outputLength:(int*)outLen;

这不管用。我做错了什么?我认为问题在于
(unsigned char*)
是错误的。如果
(unsigned char*)
是错误的,那么我认为我还需要更改方法中引用
输出的方式。如何分配?

这取决于您如何处理内存分配

-encryptake1:
返回什么?如果它返回调用者必须释放的新分配的缓冲区,那么您将在encryptTake2中使用
unsigned char**

-(int)encryptTake2:(unsigned char *)input inputLength:(int)inLen output:(unsigned char **)outputPtr outputLength:(int*)outLen
{
    *outputPtr = malloc(1024);
    unsigned char* output = *outputPtr;
    strcpy(output, "hello");
    ...
}

谢谢-就这样!我也对调用函数中的
&
*
感到困惑。在调用函数中,var被定义为
无符号字符*
,并在函数调用中以
&
作为前缀。在
encryptTake2:
中,对var的所有引用都以
*
作为前缀。我需要重读C语言书的第五章。