简体   繁体   English

c - const char *和char * casting(ADPCM解码)

[英]c - const char* and char* casting (ADPCM decoding)

Here is the objective-c sister question, which might provide some insight: c and objective-c -- const char* and char* 这是objective-c姐妹问题,它可能提供一些见解: c和objective-c - const char *和char *

I am doing the following: 我正在做以下事情:

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);

The function declaration is: 函数声明是:

void      
adpcm_decoder(indata, outdata, len, state)      
    char indata[];      
    short outdata[];      
    int len;      
    struct adpcm_state *state; 

g_ADPCMstate is the global instance variable for a adpcm_state struct. g_ADPCMstate是adpcm_state结构的全局实例变量。 http://codepad.org/5vyd0CXA is the full code. http://codepad.org/5vyd0CXA是完整的代码。 The function crashes when *outp++ = valprev; *outp++ = valprev;时函数崩溃*outp++ = valprev; happens and I get a BAD ACCESS statement from my debugger. 发生了,我从我的调试器得到一个BAD ACCESS语句。 outp is a pointer to outData while valprev is a long. outp是指向outData的指针,而valprev是一个long。

The problem has to be in my understanding of pointers and either modulatedBytes and/or decompressedBytes 问题必须在于我对指针以及modulatedBytes和/或decompressedBytes理解

I have little understanding of C and lower level concepts. 我对C和低级概念了解甚少。 I would love some insight into my problem. 我希望能够深入了解我的问题。

You pass short *decompressedBytes = NULL; 你传递short *decompressedBytes = NULL; as the outdata argument to adpcm_decoder() , and then try to dereference it. 作为adpcm_decoder()outdata参数,然后尝试取消引用它。 Did you forget to allocate decompressedBytes ? 你忘记分配decompressedBytes吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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