[Icc-avr] Accessing only the LSByte of a long
Sergio Paulo Sider
sergiosider at gmail.com
Thu May 31 09:49:16 PDT 2007
Hi All,
I would use also "unions", but you are correct, it depends on the
endianness of the compiler. But on my work, I think the benefits of
this (macro or union) approach are greater than the portability
problems it would create. A good comment is really required..
Regards,
Sergio.
On 5/31/07, John Baraclough <j_baraclough at zetnet.co.uk> wrote:
> Be careful with this macro as its success depends on the endianness
> of the particular processor/compiler combination you are using. It
> may very well fail with a change of either. As long as you make sure
> that you get the correct offsets for your setup, you'll be fine, but
> don't be surprised if it goes wrong somewhere down the line when
> someone else tries to maintain your code later. Make sure you comment
> this macro prominently.
>
> All the best for now,
> John
>
> At 16:39 31/05/2007, you wrote:
> >Hi John,
> >
> >Here's a macro I use often to get bytes from longer words:
> >
> > // fast byte access to multi-byte values
> >
> > #define get_byte(_x, _y) (*((volatile unsigned char *)(&_x) + _y))
> >
> >HTH.
> >
> >Bruce
>
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
>
More information about the Icc-avr
mailing list