c and objective-c — const char* and char*

可紊 提交于 2019-12-12 00:34:31

问题


I have a function:

-(void)ADPCMDecode:(char *)indata : (short *)outdata :(long)len {

indata is a char and the function does pointer arithmetic to iterate for a length of len, modifying outdata, which is a short and I will need to do pointer arithmetic to get the values from it.

I am attempting to call the function using:

const char *modulatedBytes1 = [modulatedAudio bytes];
char *modulatedBytes [] =  modulatedBytes1;
unsigned int moduleatedLength = [modulatedAudio length];
short *decompressedBytes = NULL;

[self ADPCMDecode:modulatedBytes :decompressedBytes :moduleatedLength];

DLog(@"%hi",decompressedBytes[1]);

I get a BAD ACCESS error on this line: *outp++ = valprev; within the function, because I am passing a constant char * instead of a char *

How should I call the function, and how would I get the output from it? I have no background in C, which is why I do not understand how to go about doing this.

Here is the C only version of the same question: https://pastee.org/d3y3z

来源:https://stackoverflow.com/questions/18883503/c-and-objective-c-const-char-and-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!