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

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

Re: [avr-gcc-list] integer overflow compiler warning?


From: Volkmar Dierkes
Subject: Re: [avr-gcc-list] integer overflow compiler warning?
Date: Tue, 31 Dec 2002 11:36:22 +0100
User-agent: 40tude_Dialog/2.0.3.1 Hamster/2.0.0.0

Hi Sander,

On Tue, 31 Dec 2002 00:53:18 -0800, Sander Pool wrote:

...
> #define UART_BAUD_SELECT ((F_CPU/(UART_BAUD_RATE*16))-1) ...
> If I use Volker's definition (F_CPU/(UART_BAUD_RATE*16l)-1) then the value
> is set correctly and no warning is generated. When I do the math by hand
> using this formula I don't get 25 at all.
>
> What's going on? Anyone have any ideas? Is gcc so limited in its constant
> calculations that it overflows that easily? How does Volker's macro work?

I think that integer is the default type for values. Therefore the 
multiplication UART_BAUD_RATE*16 is to big (153600 which is greater 
than 32767). You have to use long ints for that calculation and 
convert it later to a byte value (or 12bit for ATmega128). Therefore 
use 16L and also 4000000L for the value and F_CPU to get correct 
calculation.

HTH

Volkmar
avr-gcc-list at http://avr1.org



reply via email to

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