> Ian is close to how I would have handled it. I use a "union32_t" type  
> a fair bit in my code for no other purpose than to pluck values out  
> of the middle painlessly.
> 
> typedef union union32_t {


Okay, I think I can "see the light" about unions now, thanks to David
Kelly and Bernard who hammered it into my brain ;-) and thanks to the
many other people who suggested unions, both on and off list...
I played with them for an hour and find them so many advantages over
obscure shifts, that I love them now... :-)

Works like a charm and produces the best possible code:

                if (addr.u8.c & 0x04)
    2830:       80 91 83 01     lds     r24, 0x0183
    2834:       82 ff           sbrs    r24, 2
    2836:       02 c0           rjmp    .+4             ; 0x283c

only loads the required byte, and performs a straight forward bit test
directly on it, with this lovely sbrs instruction.


Thanks all for the hammering, you didn't waste your time ;-)


--
Vince



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to