Originally Posted by
unkownname
Alright I get your point it just seemed to work Dont get all flamy at me. your forgetting the reason for this post.
One more thing I know its illegal first of all But its being decalred after it has x and y so wouldnt that make it legal?
The reason that the standard disallows you from doing this is a bit like a stupidity protection system - the compiler has no guarantee that the non-const variable will not be changed afterwards.
The "stupidity protection" is for people who might otherwise try something like this:
Code:
int y=5;
int x[y];
// code to populate x goes here..
// "oh, i want to resize my array.. i'll just do this..."
y=7;
x[6] = 42;
// Bad, bad, bad..
There may actually be other good reasons why the standard was written this way, but this is a good enough reason IMHO