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

2019-08-29 07:48发布

问题:

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