[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Bug in shift operation with avr-gcc
From: |
Dmitry E. Oboukhov |
Subject: |
Re: [avr-gcc-list] Bug in shift operation with avr-gcc |
Date: |
Tue, 7 Jun 2011 22:22:18 +0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
> uint32_t t1;
> int main(){
> t1=0xf << (12); // t1 gets fffff000 instead of 0000f000
> }
try
t1 = ((uint32_t)0xF) << 12;
preprocessor uses int (==int16) by default so
0xf << 12 == 0xf000;
then it converts the result to uint32.
and You have the result :)
--
. ''`. Dmitry E. Oboukhov
: :’ : email: address@hidden jabber://address@hidden
`. `~’ GPGKey: 1024D / F8E26537 2006-11-21
`- 1B23 D4F8 8EC0 D902 0555 E438 AB8C 00CF F8E2 6537
signature.asc
Description: Digital signature