Possible Duplicate:
In C++ books, array bound must be constant expression, but why the following code works?
I do this within main():
int i = 2; //not constant expression
int foo[i]; //no error?
This doesn’t give me an error as it should according to my book. Why?
(i’m on clang 3.1)
Compile it with strict warnings enabled.
-pedanticif you use gcc and it will give you an error.Most compilers support variable length arrays(VLA) through a language extension. However the C++ language standard does not support VLA as a part of the language.