|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-10-30 14:22:06
"Thorsten Ottosen" <nesotto_at_[hidden]> writes:
> "David Abrahams" <dave_at_[hidden]> wrote in message
> news:uznfj5zc0.fsf_at_boost-consulting.com...
>> "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.
>
> so where should I use unsigned?
It's somewhat of a religious issue, but I use unsigned integers
wherever I am representing a number that only makes sense when
positive, as in an index into an array, a size of a datatype, etc.
This is basically the same convention used by the standard libraries,
except where "old-fashioned" interfaces like getc() and string::npos
are concerned.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk