From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-10-31 08:38:12
"David Abrahams" <dave_at_[hidden]> wrote in message
> "Peter Dimov" <pdimov_at_[hidden]> writes:
> > David Abrahams wrote:
> >> "Thorsten Ottosen" <nesotto_at_[hidden]> writes:
> >>>> what it wrong with this and why do you want to use int instead?
> >>> Basically I want to use int whereever posisble so I don't have to
> >>> worry about signed to unsiged conversions. The fact that the
> >>> standard library does so/allows just makes programming harder that
> >>> it has to be.
> >> A tendency to use ints everywhere makes that a self-fulfilling
> >> prophecy. You can turn on warnings to catch the problems. If
> >> you're consistent about using unsigned for unsigned numbers, as
> >> with const, you'll find that the actual cases where signed/unsigned
> >> conversions need to be performed a much fewer.
> > A rare case where I disagree with Dave.
> I don't think we're actually disagreeing.
> > It is almost never necessary to use unsigned types in numeric
> > contexts (as opposed to bit fiddling), and there are plenty of
> > reasons to actively avoid them. For example, -1 / 4u or 1u
> >> -1.
> Yep, those are the ones which good compilers can warn about, also.
which is less fortunate if you compiler don't or if you're not experienced
deal with this issue.
> > Unsigned types aren't "const correct" since the conversions are
> > often silent and safe.
> Optional warnings aside, that's right. I was just saying that
> consistent use of unsigned in the appropriate places often makes
> signed/unsigned interactions rarer when you are forced to use them
> anyway at std:: library interface boundaries.
> Note that signed integers aren't exactly safe either. Underflows and
> overflows typically pass without notice, for example.
If I remember the threads correctly, then overflow is undefined for signed
types; the program might crash it might not.
AFAIR, underflow only happens with floating point numbers.
As far as safety is a concern, then I would have thought that you would have
wanted the safe variant to be the
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk