|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-01-18 13:06:06
Gennaro Prota <gennaro_prota_at_[hidden]> writes:
> On Tue, 14 Jan 2003 17:11:39 -0500, David Abrahams
> <dave_at_[hidden]> wrote:
>
>>Gennaro Prota <gennaro_prota_at_[hidden]> writes:
>>> As I think you all know, if you have something like
>>>
>>> enum e { e1 = 1u << 31 };
>>>
>>> then it simply "promotes" e1 to int instead of unsigned int. For
>>> instance this
>>>
>>> enum e { e1 = 2147483648u };
>>>
>>> #include <iostream>
>>>
>>> int main() {
>>> std::cout << e1 << '\n';
>>> }
>>>
>>> outputs -2147483648. Applied to my code, where I have e.g.
>>
>>Are you sure the promotion doesn't happen when e1 is passed to the
>>streaming operator?
>
> I'm afraid I don't understand your question. Maybe you are asking
> whether the compiler is just favoring conversion over promotion? I
> don't think so. I think the problem is that they just consider int as
> the underlying type, always. The overall effect however is
> more-or-less the same than if they always converted to int. As a
> further example, this executes the if-branch:
>
> if ( (e1 + 0) < 0)
> std::cout << "Bad promotion...\n";
Right. But does it print anything in this case?
if (e1 < 0)
std::cout << "whoops\n";
Then I'd be worried.
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk