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: Royce Pereira
Subject: Re: [avr-gcc-list] Warning message
Date: Wed, 03 Oct 2007 20:49:31 +0530
User-agent: Opera Mail/9.22 (Win32)

Hi,
On Wed, 03 Oct 2007 19:57:54 +0530, David Kelly <address@hidden> wrote:

> 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)
>
Actually this worked:

Changing the offending line to:

if(twi_read() != (uint8_t)~CHK_1307) ok= 0;

Thanks to all,
--Royce
-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




reply via email to

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