g ++变量大小数组没有警告?

Far*_*her 4 c++ memory heap g++

int a;
cin >> a;
int ints[a];
Run Code Online (Sandbox Code Playgroud)

为什么在编译时不会抛出任何警告?我如何知道这个数组的实际使用时间是堆还是堆栈?

g++ -std=c++11 -Wall *.cpp -o main

Fil*_*efp 8

ISO C++不允许使用可变长度数组,g++如果你通过传递-pedantic标志来增加它的严格性,它会很高兴地告诉你.

使用-pedantic将发出违反标准的警告.如果你想g++发出错误并且因为这样的事情而使用这个垃圾编译; 用-pedantic-errors.


g++ -Wall -pedantic -std=c++11 apa.cpp
Run Code Online (Sandbox Code Playgroud)

apa.cpp: In function ‘int main(int, char**)’:
apa.cpp:8:13: warning: ISO C++ forbids variable length array ‘ints’ [-Wvla]
   int ints[a];
             ^
apa.cpp:8:7: warning: unused variable ‘ints’ [-Wunused-variable]
   int ints[a];
       ^
Run Code Online (Sandbox Code Playgroud)