"Default User" <> wrote in message
news:...
> John Brawley wrote:
>
> > I don't know if this is the same idea, but I do exactly this with an
> > array[].
> > My program can't grab the necessary memory until the user enters a
> > number so the program can provide it for what comes later.
> > I was told the only two ways to do this were an array[] and a
> > vector[], and I had to create the array[] with *new.
>
> It's an extension. It's not standard, and so it is not portable. If you
> use it in g++, it may not work with another compiler. It won't work if
> instruct g++ to adhere to standards.
>
> In C, there is now a construct called "variable length arrays". Those
> are not part of C++. The only portable way to do it is with std::vector
> (and you should have really good reasons for not using that in the
> first place) and a pointer with new.
> Brian
(!) I did not know it was nonstandard, nor that it would be nonportable.
The question arises though: _how_ nonportable? The machines this program
has run on all run it perfectly, but they were probably all Windows machines
(it ran on 95, 98(mine), and XP, and ported with minor mods not including
replacing the *new array[], to Linux, so I'm not sure how dangerous my *new
array[] really is.... Is there some way for me to tell how nonportable I've
made this thing?, besides the various people and machines it ran on?
(My reasons for not using vectors were 1) I didn't understand how at the
time and b) I read that if you resize a vector downward it's possible to
"lose" pointers' ties into it, and c) the original was written in Python
(this C++ is a translation), which itself wears C underpants, and I was
familiar with Python's "lists{}"' and "dictionaries[]"' identical
accessing-and-storing syntax.
Perhaps if I rewrite it again (only for _speed_, only for _speed_ (*g*)),
I'll try it with vectors.
--
Peace
JB
|