avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] I Think This Is A Bug


From: Curtis Maloney
Subject: Re: [avr-gcc-list] I Think This Is A Bug
Date: Tue, 05 Apr 2005 12:57:21 +1000
User-agent: Debian Thunderbird 1.0.2 (X11/20050331)

David Kelly wrote:
Avr-gcc doesn't doesn't fully evaluate this expression which should
reduce to 113. The FreeBSD version of gcc has no problem, but both the
FreeBSD ports version of avr-gcc and current WinAVR avr-gcc behave
identially (wrongly) the same:

Hello, and welcome to the world of "Not everyone uses 32bit ints.". AVR ints are 16bit. Pay attention to the warnings. Warnings are your friends.

> unsigned long ulval;
> unsigned char ucval;
>
> junk()
> {
>         ucval = (1+(7372800L/(256*256)));
>         ulval = (1+(7372800L/(256*256)));
> }

GCC is seeing 256 * 256, as the integer multiplication of two 16bit values. 0x100 * 0x100 = 0x10000... oops, that won't fit into 16bits! And thus, the overflow warnings you see here:

junk.c:6: warning: integer overflow in expression
junk.c:6: warning: integer overflow in expression
junk.c:6: warning: large integer implicitly truncated to unsigned type
junk.c:7: warning: integer overflow in expression
junk.c:7: warning: integer overflow in expression

Solution?  Mark the 256s as Longs, and see how it goes.

--
Curtis Maloney
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]