Similar to the question Bitshift and integer promotion?, I have a question about integer promotion when using left bitshifts.
unsigned int test(void)
{
unsigned char value8;
unsigned int result;
value8 = 0x12;
result = value8 << 8;
return result;
}
In this case, will be the value8 first promote to unsiged int or is it implementation specific?
6.5.7 Bitwise shift operators ... 3 Sematics ...
The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.
It says that the "The integer promotions are performed on each of the operands.", but what is here the promotion rule?
I assume that it should be convert to int if lesser rank than int
, but I can't find it.
I ask this, as one compiler (Renesas nc30wa) doesn't promote to int, so the result is always 0 for my sample.
On this platform, a char is 8 bit wide and int 16 bits.
result16
and useresult
- this won't compile. – ugoren