我们有一段C代码如下任何解决方案都已声明并初始化

void fillProcess(void *unused, Uint8 *stream, int len)
{
    Uint8 *waveptr;
    int waveleft=0;

    waveptr = wave.sound + wave.soundpos;
    waveleft = wave.soundlen - wave.soundpos;
    while ( waveleft <= len ) {
    /* Process samples */
    Uint8 process_buf[waveleft];
    SDL_memcpy(process_buf, waveptr, waveleft);
    /* do processing here, e.g. */
    /* processing the audio samples in process_buf[*] */
    // play the processed audio samples
    SDL_memcpy(stream, process_buf, waveleft);
    stream += waveleft;
    len -= waveleft;
    // ready to repeat play the audio
    waveptr = wave.sound;
    waveleft = wave.soundlen;
    wave.soundpos = 0;
    }
}

得到3个错误,如下所示
Error   1   error C2057: expected constant expression
Error   2   error C2466: cannot allocate an array of constant size 0
Error   3   error C2133: 'process_buf' : unknown size

最佳答案

Uint8 process_buf[waveleft];

该行使用可变长度数组,这是在C99中引入的但是根据错误代码,您使用的是Visual Studio,它还不支持C99。
假设编译器仍然是Visual Studio,则可以动态分配process_buf

关于c - 期望常数表达式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19210597/

10-16 18:28