From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-03-23 06:38:53
On Wed, Mar 23, 2005 at 02:12:03PM +0300, Vladimir Prus wrote:
> Hi Jonathan,
> > The attached patch fixes a 64 bit portability problem where
> > std::string::size_type is assigned to unsigned, which is shorter
> > than size_t on x86-64 and so will be truncated. This means the
> > following comparison to std::string::npos is always false.
> Applied. Interesting, I'd say that a std::string of more that 4GB is a
> terrible idea, performance wise, as many operations are linear on string
> size. Do you know why it's decided to make size_type 64bit?
size_t must be 64-bit or you couldn't request >4GB from new and malloc.
IIRC std::string::size_type must be std::size_t.
AFAIK there's no requirement that std::string::max_size() == 4GB,
even though the return type is large enough to hold that value, so an
implementation could restrict strings to reasonable sizes, it just can't
use a 32bit type to report the size.
> > Patch also prevents a warning with GCC; since the compiler doesn't
> > know that boost::throw_exception never returns it thinks that
> > cmdline::translate_property() can reach the end of the function without
> > returning. The patch simply removes the "else" so that throw_exception
> > is always called if control reaches the end of the function. A better
> > solution might be to mark boost::throw_exception() with
> > __attribute__((unused)) for GCC.
> Shouldn't it be
duh! yes, of course. My fingers took a short cut that avoided my brain
and typed something else I was thinking about!
-- VOTE, v. The instrument and symbol of a free man's power to make a fool of himself and a wreck of his country. - Ambrose Bierce, 'The Devil's Dictionary'
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk