自从什么时候这是有效的语法?(在使用g ++ 4.6.3时有效)我应该搜索什么以获取更多关于此的信息(我习惯于使用new/delete)?
#include <iostream>
int main(){
size_t sz;
std::cout<<"number?\n";
std::cin>>sz;
// This line
float dynamic_arr[sz];
//output the (uninitialized) value just to use the array.
std::cout<<dynamic_arr[0]<<std::endl;
return 0;
}
std::vector<float> dynamic_arr(sz);
不能为您工作的原因,但我想不出来。嗯,对于sz == 0
,我想你会很困扰,但是如果使用VLA,您的代码也会一样,所以...没什么问题。 - WhozCraig__attribute__(aligned(32))
以针对IPP库进行优化;因此作者更喜欢使用固定大小的数组。 - Dave