Hello, I am having a problem using bit shift operators on unsigned 32-bit integers. Here is the problem. I am programming for avr mega2560. I am using Atmel Studio 6.2 with the latest 8-bit toolchain available through the extension manager. When I do the following:
unsigned long my_var = 0;
my_var |= 0x00000001 << 16;
The compiler gives the following warning:
my_program.c:22:1: warning: left shift count >= width of type [enabled by default] my_var |= ( 0x00000001 << 16);
The value stored in my_var after this operation is: 0xFFFF0000. Bit shifting by more spaces causes the bit I want to set AND every higher-numbered bit to all be set to '1'. I get the same behavior when using the explicit uint32_t type (I realize this is just a typedef of unsigned long). I have also tried shorter bitmasks, ie. 0x01. Same result.
I cannot figure out why this is happening. If I bit shift by <16 spaces everything is fine. It stops working when shifting by 16 spaces or more.
Can anyone explain what is going on?
On a (perhaps) related note I see that there is a new version of AVR 8-bit toolchain available to download from Atmel on their web site as of 11/2014, but this version is not available in the Atmel Studio Extension Manager. The splash on the avr-gcc I'm using shows (from Atmel Studio) shows the following version at compile time: AVR_8_bit_GNU_Toolchain_3.4.4_1229. I downloaded the new version, and "avr-gcc -v" gives the following: AVR_8_bit_GNU_Toolchain_3.4.5_1522. Both are gcc version 4.8.1. I'm not 100% sure how I'd overwrite the older version without messing up my environment but I'm willing to give it a shot if anyone thinks it might help & cares to walk me through it.