John said:
Ian Collins said:
John Brawley wrote:
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?
It's portable to anywhere were the compiler you compiled it with has a
port...
Ian Collins.
Uh... please pardon: I don't follow....
Compiler: Borland command line tools v5.5 (BCC32).
How, pray tell, does somewhere else have a "port" specific to a compiler?
(Pardon also: I have a sneakin' suspicion that was humor, but I'm not
sure....)
The language extension you're using is a feature of the compiler, not
the platform. If you run the same compiler on a different platform, the
behavior will generally be the same as on the first platform.
Similarly, if you use a compiler that takes a stricter view of
variable-length arrays, it should give you the same diagnostic on any
platform to which it has been ported.
If Borland v5.5 was written for Windows 95, but runs on Linux, then it
is said to have been "ported" to Linux, or to have a "port" on Linux.
If it has been officially ported to BSD, then it will exist in the BSD
"ports" tree. If it has been formally ported to Gentoo, then it will
exist in a system called "portage." GCC was not originally written for
Windows, but does have a port to it.