我们有一段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;
}
}
Run Code Online (Sandbox Code Playgroud)
获得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
Run Code Online (Sandbox Code Playgroud)
Uint8 process_buf[waveleft];
Run Code Online (Sandbox Code Playgroud)
该行使用可变长度数组,该数组在C99中引入.但是根据您的错误代码,您使用的是Visual Studio,它还不支持C99.
假设编译器仍然是Visual Studio,您可以process_buf动态分配.