Boost logo

Boost Users :

From: Asif Lodhi (asif.lodhi_at_[hidden])
Date: 2008-08-18 19:03:18


Hi Zeljko,

On 8/17/08, Zeljko Vrba <zvrba_at_[hidden]> wrote:
> On Sat, Aug 16, 2008 at 11:50:05PM +0300, dizzy wrote:
>> ..................................
> times in the past by implicit signed -> unsigned conversions in relational
> comparisons. The most sane thing would be to throw an exception at runtime
> if
> one compares a negative integer with some unsigned quantity, instead of
> getting
> false for '-1 < 2U', which is a mathematical nonsense. signedness of a type
> *should not* affect its numerical value in mathematical operations.

I would like to explain explicitly that the int to unsigned int
conversion is NOT by accident - it is a "Standard Conversion" and you
can find it in Appendix "C" of the book "The C++ Programming Language,
3rd Ed." (TC++PL) by Bjarne Stroustrup. In appendex C of TC++PL,
almost all types of conversions are defined, AFAIK. Once you _know_
that it happens then writing something like "-1 < 2U" is entirely your
problem to take care of as compiler, IMO, is not likely to issue any
warnings because you are explicitly specifying 2 as an unsinged
constant by suffixing "U" to it which will automatically convert the
-1 to an unsigned bitwise (as a Standard Conversion) because of
closeness of the language to the machine which was a huge factor in
the language design (you can read Stroustrup's book: "Design and
Evolution of C++" to verify that). As you and others have already said
earlier, you can always design a new class if you want to make
mathematical sense.

-Asif


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net