Boost logo

Boost :

Subject: Re: [boost] Algebraic abstractions related to (big) integers in C++
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2011-03-29 17:06:59


Thomas Klimpel wrote:
> Brent Spillner wrote:
>> Note also that (at least in ANSI C) when performing
>> arithmetic between an unsigned value and a signed value of higher
>> rank, the promotion is to the signed type--- so the "promote to the
>> 'larger' type" principle is consistently applied across the board,
>> particularly if you consider unsigned types "larger" than the signed
>> equivalent (seems reasonable to me given how uncommon negative values
>> are in most integer code.)
>
> You're kidding, right?

I've heard this rationale before. He is serious. Promoting 32 bit unsigned to 32 bit signed, for example, could overflow, so is clearly not safe. Promoting signed to unsigned is just as bad, of course, but it won't overflow. I'd like a compiler warning for all auto promotion of signed to unsigned so that I can inspect the line and see if I think it is safe. If it happens when you didn't realize it would it is usually unsafe. If it happens when you realize it would you might as well make it explicit since you gave it enough thought to know it was safe. We have our promotion rules inherited from C, so we can't fix them any more than we can fix the linker. The rules don't specify what a warning is, though, and warnings are errors for us pedantic people. To some extent we get to make our own rules. As far as I'm concerned implicit cast from signed to unsigned is illegal.

Regards,
Luke


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