How do compilers treat variable length arrays

前端 未结 4 1762
自闭症患者
自闭症患者 2020-11-30 13:59

This might seem like a beginner\'s question, but I am interested in the way that a compiler normally creates arrays of variable-dimensions, like in the following program.

4条回答
  •  渐次进展
    2020-11-30 14:34

    int main(){
      int n;
      std::cin>>n;
      int a[n];
    }
    

    This is not legal C++. G++ accepts Variable Length Array's as an extension but VLAs are not part of the C++ standard. They are part of the C99 standard which GCC supports(I am not sure to what extent) but MSVC doesn't.

提交回复
热议问题