On 11/27/18 8:41 PM, David Gibson wrote:
On Wed, Nov 28, 2018 at 01:32:21PM +1100, Benjamin Herrenschmidt wrote:
On Wed, 2018-11-28 at 11:13 +1100, David Gibson wrote:
Don't you need a cast to avoid (nsr << 8) being a shift-wider-than-size?

Shouldn't be a problem as long as it fits in an int, no ?

I dunno, I can never remember the rules about when C extends and when
it doesn't.  I'm not sure anybody does, which is kind of the point.

As soon as you perform arithmetic on a type narrower than int, it is first promoted to at least int (possibly wider, depending on the type of the other operand to the binary operator). And, since C guarantees that int is larger than 8 bits, 'uint8_t << 8' and 'int8_t << 8' are both well-defined, without needing a cast of nsr.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Reply via email to