Boost logo

Boost :

Subject: Re: [boost] [xint] Design Question
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2010-06-17 12:04:05


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/17/2010 07:10 AM, Stewart, Robert wrote:

>>> What about making the difference between two unsigned integers a
>>> signed integer?
>>
>> That sounds like a useful behavior, but if the developer using the
>> library says it should be an unsigned number, I don't think the
>> library should override that.
>
> According to an old C book I have (C: A Reference Manual, 2nd ed,
> Harbison and Steele), "the result of subtracting one unsigned integer
> from another is always unsigned and therefore cannot be negative."

Yes, that's the way I've always understood it. I've often taken
advantage of that too -- typecasting -1 to an unsigned type gives a
value with all bits on, and doesn't require you to know how many bits
that type has beforehand. (Yes, there are other ways to do it, like with
operator~.)

> That may not be definitive, and the C++ standard doesn't dictate the
> type of the result other than, perhaps, by incorporating the C
> standard to which I have no access, but it certainly sets
> expectations that your library ought not violate.

Pretty much what I was thinking.
- --
Chad Nelson
Oak Circle Software, Inc.
*
*
*
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwaR3IACgkQp9x9jeZ9/wRuJwCgtAfWrgJyNbq9BH3Sn3Cl/Vpu
bO0AoPy4wtImsWECayMJgqmcfcdtWVnm
=WIg2
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk