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


From: Bruce D. Lightner
Subject: Re: [avr-gcc-list] integer overflow
Date: Tue, 27 May 2003 13:06:51 -0700

Ömer,

> i have an overflow warning from the compiler
> here is the code that makes the problem
> unsigned long val;
> 
> val = 1000*60*60*24;
> 
> i think the problem stems from the sizeof long , as far as i know long
> is 4 bytes for atmel processors and integer is 2 bytes.the maximum
> value for 4 bytes is
> 
> FFFFFFFF which is 4,294,967,295 that is bigger than 86,400,000.
> 
> if long is 2 bytes than is there a built in structure for carrying 4
> bytes ?

Try...

  val = 1000L*60*60*24;

"Ints" are 2 bytes with "avr-gcc".  Integer constant expressions therefore
use only 2 bytes, unless you somehow promote the expression evaluation to
use 4-byte longs.  Replacing 1000 by 1000L will cause this to happen. 

Best regards,

Bruce

P.S.- There are many other ways to do this, which I'm sure Joerg will soon
share with you...

-- 
 Bruce D. Lightner
 Lightner Engineering
 La Jolla, California
 Voice: +1-858-551-4011
 FAX: +1-858-551-0777
 Email: address@hidden
 URL: http://www.lightner.net/lightner/bruce/


reply via email to

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