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

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

Re: [avr-gcc-list] 8 bit bitwise operation promoted to 16 bit values


From: Neil Johnson
Subject: Re: [avr-gcc-list] 8 bit bitwise operation promoted to 16 bit values
Date: Sun, 26 Oct 2003 18:44:36 +0000 (GMT)

Hi,

> Won't this always evaluate to false unless (LN_TX_BIT == LN_RX_BIT)?
>
> The only way I can see this working is like this:
>
>      if ( LN_TX_PORT & ( 0x01 << LN_TX_BIT ) &&
>           LN_RX_PORT & ( 0x01 << LN_RX_BIT ) )
>      {
>          ...
>      }

Indeed this would be better.  I constructed my example as close as
possible to the original so that the OP would see the important difference
to get the compiler to generate 8-bit code.  Nothing was discussed about
the correctness....  ;-)

> Likewise here since bit_is_set() is defined by avr-libc thusly:
>
>   #define bit_is_set(sfr, bit)   (sfr & _BV(bit))
>
> Again, I think replacing '==' with '&&' will correct the code.

Ditto.  Now, if we are to discuss the _correctness_ of the code, that is a
different question from the one originally asked.
(Can you tell I'm in pedantic mode today?  Jeez, I think I should get out
more.... *sigh*)

> Other than those logical errors, I think Neil's comments ring true.

Thanks :-)  A brief respite from writing up :-(

Cheers,
Neil

--
Neil Johnson :: Computer Laboratory :: University of Cambridge ::
http://www.njohnson.co.uk          http://www.cl.cam.ac.uk/~nej22
----  IEE Cambridge Branch: http://www.iee-cambridge.org.uk  ----


reply via email to

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