我知道sizeof
是编译时运算符,那么为什么这段代码可以正确编译和运行而没有任何警告呢?
#include <iostream>
int main() {
int size;
std::cin >> size;
int array[size];
std::cout << sizeof(array) / sizeof(int) << std::endl;
}
g++ -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)