This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++/7972: > v.size(), where v is vector, incorrectly returns true

The following reply was made to PR libstdc++/7972; it has been noted by GNATS.

From: Phil Edwards <>
Subject: Re: libstdc++/7972: > v.size(), where v is vector, incorrectly returns true
Date: Wed, 18 Sep 2002 19:29:14 -0400

 On Wed, Sep 18, 2002 at 04:13:29PM -0000, wrote:
 > >Description:
 > (I am not sure about what the Submitter-Id is.)
 It's handled automatically if you use the normal bug reporting mechanisms.
 (And you did.)
 > It appears that a program will incorrectly return true at least for
 > an if statement, if(i > v.size()) where i is an integer of some value
 > less than the size of a vector, v. This exact same problem is found in
 > Microsoft's Visual C++ 6.0 compiler. I also reported it to them, and noted
 > the co-existence in the gnu compiler. (It is hard not to conclude that
 > someone copied from someone else,
 Faulty logic.  The only common code in this case is /yours/.  :-)
 > (I am suspecting that the '>' operator is simply overloaded improperly
 > for whatever type vector::size() returns.)
 There's no overloading.  The type involved will be something like
 "unsigned int".
     % g++-3.2 -Wall -W warning: ISO C++ forbids declaration of `main' with no type In function `int main()':
 -> warning: comparison between signed and unsigned integer expressions
 Declare structnumber as "std::vector<double>::size_type" instead of int,
 and you won't have this problem.  (Yes, some typedefs will help you
 reducing typing.)
 I would therefore like to posit that computing's central challenge, viz. "How
 not to make a mess of it," has /not/ been met.
                                                  - Edsger Dijkstra, 1930-2002

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]