From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-10-30 09:08:05
"Wynand Winterbach" <wynand_at_[hidden]> wrote in message
> On Wed, Oct 29, 2003 at 10:13:14PM -0700, Dave Gomboc wrote:
> > > so where should I use unsigned?
> > >
> > > -Thorsten
> > Use unsigned numeric types whenever negative values aren't
> > permitted or don't make sense.
> > Dave
> I quote Bjarne Stroustrup (page 73, The C++ Programming Language, Third
Actually, one of the to threads I mentioned was called "unsigned vs signed -
Is Bjarne Mistaken?"
I believe the answer is "no".
> "The unsigned integer types are ideal for uses that treat storage as a bit
> Using an unsigned instead of an int to gain one more bit to represent
> integers is almost never a good idea. Attempts to ensure that some values
> positive by declaring variables unsigned will typically be defeated by the
> implicit conversion rules"
> As an example that got me when I started programming, consider the
> seemingly innocuous case:
> char blah;
> for ( unsigned i = 5; i >= 0; i-- )
> cout << blah[i];
> This fails i can never become -1. Actually, you'll have an infinite loop.
there was a lot of similar examples in the threads.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk