c - const char* 和 char* 转换(ADPCM 解码)

标签 c char constants exc-bad-access short

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

最佳答案

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

关于c - const char* 和 char* 转换(ADPCM 解码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18939572/

相关文章:

c - 如何将 3D 字符数组传递给函数

C 用已知的最大长度逐个字符构建字符串

c - C 中的指针整数字符警告

计算 C 中 char 数组的离散值

c++ - 来自 std::set insert() 和 find() 的写-写数据竞争?

c - 如果需要调用copy_to_user,如何使用自旋锁?

C++ 与 Dll 通信出错

c++ - 用 const std::vector 包装现有内存?

python - 在 Django 中存储常量的最佳方式