【问题标题】:c - const char* and char* casting (ADPCM decoding)c - const char* 和 char* 强制转换(ADPCM 解码)
【发布时间】:2013-09-27 04:30:25
【问题描述】:

这是objective-c 姊妹问题,它可能会提供一些见解: c and objective-c -- const char* and char*

我正在做以下事情:

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 和更低级别的概念知之甚少。我希望能深入了解我的问题。

【问题讨论】:

    标签: c char constants exc-bad-access short


    【解决方案1】:

    您将short *decompressedBytes = NULL; 作为outdata 参数传递给adpcm_decoder(),然后尝试取消引用它。忘记分配decompressedBytes了吗?

    【讨论】:

    • 我应该把它分配成什么?我应该在其中存储随机位吗?
    • @stackOverFlew 只需使用malloc() 分配它,然后让adpcm_decoder 负责初始化它(通过*outp++ = valprev 行)。
    猜你喜欢
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 2013-12-31
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多