Strange Shift Warning

I am getting this warning:

warning C200: '>>': out of range shift factor has been truncated

with regards to this line of code:

Mbuf[1] = HEX2ASCII( (pEvent->num & 0xF000) >> 12 );

This warning does not appear when the identical project is compile on other machines!

Any ideas?

Rich

Parents
  • The error message leads me to think the compiler sees the LHS of the shift as a byte; a 12-bit shift would be "out of range". I'm not sure what other meaning "out of range" would have with respect to a shift.

    Perhaps the definition of the HEX2ASCII macro inclues a cast to a U8 (char of some sort). Check the parenthesization and precedence in the preprocessor output.

    Or, add your own parens, e.g.

    Mbuf[1] = HEX2ASCII((((U16)(pEvent->num) * 0xF000) >> 12));

    to make sure the integer widths are what you expect.

Reply
  • The error message leads me to think the compiler sees the LHS of the shift as a byte; a 12-bit shift would be "out of range". I'm not sure what other meaning "out of range" would have with respect to a shift.

    Perhaps the definition of the HEX2ASCII macro inclues a cast to a U8 (char of some sort). Check the parenthesization and precedence in the preprocessor output.

    Or, add your own parens, e.g.

    Mbuf[1] = HEX2ASCII((((U16)(pEvent->num) * 0xF000) >> 12));

    to make sure the integer widths are what you expect.

Children
More questions in this forum