|
From: Ioannis V. <no...@ya...> - 2002-02-17 17:33:33
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Devin Carless
> Sent: Sunday, February 17, 2002 6:47 PM
> To: dev...@li...
> Subject: Re: [Dev-C++] 'New Source File' bug
>
>
> Oh, I know. They're wonderful-looking things. I'm
> currently only using them as fancy dynamic arrays.
> But while you can do a lot with vectors, vectors can do a
> lot with you. I had Vec.size() in a conditional, and the
> conditional consistently got it wrong. It worked, however,
> when I replaced
> Vec.size() with a variable, Size, which had been intialized to
> Vec.size() a line before.
> That's only one reason I'm very cautious with vectors.
This is broken compiler. Did it happen with MINGW32?
Although i did not see any code, value wrapping may had occured.
E.g.
for(int i=0; i<Vec.size(); i++)
{ ...}
When variable i reached the maximum int value it may wrapped around
(according to the standard it is undefined behavior).
The correct & safe synatx is assuming Vec to be vector<int>:
for(vector<int>::size_type i=0; i<Vec.size(); i++)
{ ...}
> > Anyway i think it is our lack of knowledge, not vectors.
> When i finish
> > the 16th chapter i will resend an email telling you how you can to
> > assignments using vector constructors.
>
> There's a saying that goes 'It's a poor workman who blames
> his tools.' And many times it's been my mistake; I'm a poor
> workman. But there are other times when I've caught
> something funny going on. (push_back() refusing to work was
> one of them.)
This is broken implementation issue.
> > I am confident that standard containers are better than built in
> > arrays.
>
> Absolutely true: the reason I'm using vectors is because
> arrays are /worse./ The only thing I think arrays have to
> recommend them is that they can be intialized like so:
>
> char* frogs[4] = { "Green", "Tree", "Bull", "Muppet" };
>
> (Yes, I know char* is frowned upon, but I've found some
> interesting traps trying to initialize a string to a string
> constant of the form "Blah" when passed as an argument.)
> For my project, in which certain subclasses have great
> tracts of constant data, this kind of initialization would be ideal.
I am working using standard containers all the time and never
encountered any problem (except that MING doesn't support vector::at()
).
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
|