AFAIK this code is not a valid c++ code by standard:
int a = 5;
int b[a];
but it seems many compilers can compile that code (mostly with warning) and it just behaves as expected. Am I wrong is is it compilers being nice to me?
AFAIK this code is not a valid c++ code by standard:
int a = 5;
int b[a];
but it seems many compilers can compile that code (mostly with warning) and it just behaves as expected. Am I wrong is is it compilers being nice to me?
It is called variable length array (VLA) which is not allowed by Standard C++, any version of C++, though some GCC supports this as an extension.
If you're using GCC, then
-pedantic
option, you will see warning.-pedantic -Werror
option, you will see warning turned into error.VLA is allowed only by C99, though not by other versions of C.
The compiler is being nice. :)
It's actually part of the C standard, and some compilers (like GCC) extend C++ with this feature.