Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Order of type conversions

22 views
Skip to first unread message

Richard Hartman

unread,
Sep 10, 2015, 6:37:50 PM9/10/15
to

We have an 16-bit signed int, with value of -1.
If it gets cast to a 32 bit unsigned int, does it go:

a) convert to 16 bit unsigned (0xFFFF)
b) convert to 32 bit unsigned (0x0000FFFF)

or

a) convert to 32 bit signed (-1)
b) convert to 32 bit unsigned (0xFFFFFFFF)

and is this order fixed, or undefined (basically left up to the compiler)?

bartekltg

unread,
Sep 10, 2015, 6:49:58 PM9/10/15
to
4.7 Integral conversions [conv.integral]

2 If the destination type is unsigned, the resulting value is the
least unsigned integer congruent to the source integer (modulo 2
n where n is the number of bits used to represent the unsigned type).

So 0xFFFFFFFF.

bartekltg




0 new messages