0
下面是Objective-C的姐姐的问题,这可能会提供一些见解: c and objective-c -- const char* and char*Ç - 为const char *与char *铸造(ADPCM解码)
我做了以下内容:
g_ADPCMstate.valprev=32767;
g_ADPCMstate.index=0;
const char *modulatedBytes1 = {0xca,0x82,0x00,0x00,0x80,0x80,0x80,0x80};
char *modulatedBytes = (char *)modulatedBytes1;
unsigned int moduleatedLength = 8;
short *decompressedBytes = NULL;
adpcm_decoder(modulatedBytes, decompressedBytes, moduleatedLength, &g_ADPCMstate);
该函数声明为:
void
adpcm_decoder(indata, outdata, len, state)
char indata[];
short outdata[];
int len;
struct adpcm_state *state;
g_ADPCMstate
是一个adpcm_state结构全局实例变量。 http://codepad.org/5vyd0CXA是完整的代码。该函数在发生*outp++ = valprev;
时崩溃,并从调试器中获取BAD ACCESS语句。 outp是outData的指针,而valprev是long。
的问题必须是在我的指针的理解,要么modulatedBytes
和/或decompressedBytes
我对C缺乏了解和较低水平的概念。我很想深入了解我的问题。
我该如何分配它?我应该存储随机比特吗? – stackOverFlew
@stackOverFlew只需使用'malloc()'分配它,然后让'adpcm_decoder'负责初始化它(通过'* outp ++ = valprev'行)。 –