Re: array size known/not known in compile time
Bo Persson wrote:
Sushrut Sardeshmukh wrote:
Bob wrote:
The 1999 C (C99) standard supports declaration of an an array with
a size that is determined at run time. My guess is that you are
either compiling your code as C99, or that g++ supports this
feature as an extension.
Bob and every one else, thanks for help.
I am wondering why C++ standard wants array size to be known in
compile time.
Beacuse it is easier to handle, and it is also compatible with
C90, which is C++'s base language.
But most of the other things in C99 are being integrated into
C++.
Can some one please help me to understand why c++ standard keeps
this restriction?
Why not?
If you need a variable size array, you can use a std::vector. It can not
only be created with a variable size, it can also be dynamically resized.
That makesit much more useful.
I think that that's part of the reason. In the last version of
the standard, there was some discussion about fixing C style
arrays; the concensus was, if I'm not mistaken, is that they are
so broken that they couldn't be fixed without breaking C
compatibility, and that the best thing to do was just ignore
them---leave them as is, for C compatibility, but design a new
solution for future use.
The current position, I think, is that it is evident that the
VLA in C cannot be adopted per se---it includes things like
allowing arrays at the end of a struct to be variable length as
well, which doesn't work at all with inheritance. And that
nobody has enough interest in the question to invest the time to
define what modifications and/or restrictions are necessary to
make it work in C++.
And, of course, that we do have std::vector, which does more or
less the same thing (and can do it in the same way under the
hood).
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]