C4003: Shift count converted to unsigned char

[DISABLE, INFORMATION , WARNING, ERROR]

Description

In ANSI-C, if a shift count exceeds the number of bits of the value to be shifted, the result is undefined. Because there is no integral data type available with more than 256 bits yet, the compiler implicitly converts a shift count larger than 8 bits (char) to an unsigned char, avoiding loading a shift count too large for shifting, which does not affect the result. This ensures that the code is as compact as possible.

Example
  int j, i;

  
  i <<= j; // same as 'i <<= (unsigned char)j;'

  

In the above example, both 'i' and 'j' have type 'int', but the compile can safely replace the 'int' shift count 'j' with a 'unsigned char' type.

Tips

None, because it is a hint of compiler optimizations.