We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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 ?
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.
Should be "you exceed the range for an signed int" above.
Thank you !