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

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

Re: [avr-gcc-list] Warning message


From: David Kelly
Subject: Re: [avr-gcc-list] Warning message
Date: Wed, 3 Oct 2007 09:27:54 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Oct 02, 2007 at 11:25:30PM -0700, Dave N6NZ wrote:
> 
> >#define CHK_1307     0x55

> >      if(twi_read() != ~CHK_1307) ok= 0;
> >//   ^^^^^^
> >//        The offending line.
> I believe what is going on is the C standard requires promotion to int, 
> and that bites (bytes?) you :)
> 
> The result of twi_read() and also the ~CHK_1307 get promoted to ints 
> before comparison. So... 0x00xx from twi_read() is compared against 
> -xFFAA, which is clearly always true.

I think CHK_1307 is already an int but that it fits in uint8_t without
loss of resolution so the compiler doesn't complain. When complimented
it no longer fits so the compiler complains. I would recommend changing
its definition:

#define CHK_1307        ((uint8_t) 0x55)

-- 
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.




reply via email to

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