This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RealView warning

I have declared this variable :
unsigned int Test;

To set de MSB, i can make so :
Test |= 0x80000000;
it works ok, but if I make so :
Test |= (1 << 31), the realview compiler claims :

warning: #61-D: integer operation result is out of range
warning: #68-D: integer conversion resulted in a change of sign

But the two instructions both set the MSB, why the latter result in warning ?

Parents
  • Hi Marcelo,

    In the second case, your 1 is, by default, a signed number. When you left-shift it by 31, you exceed the range for an unsigned int - hence the warnings.

    Try :-

      Test |= ((unsigned int) 1 << 31)
    

    or

      Test |= (1U << 31)
    

    regards,

    David.

Reply
  • Hi Marcelo,

    In the second case, your 1 is, by default, a signed number. When you left-shift it by 31, you exceed the range for an unsigned int - hence the warnings.

    Try :-

      Test |= ((unsigned int) 1 << 31)
    

    or

      Test |= (1U << 31)
    

    regards,

    David.

Children