On Tue, Mar 30, 2010 at 4:10 PM, Kustaa Nyholm
<kustaa.nyh...@planmeca.com>wrote:

> Classically this has been done in C by defining a union of two chars and a
> short or int, something like:
>
> typedef union {
>        char asBytes[2];
>        short asShort;
>        } myType;
>
>
> ..
>
> myType temp;
>
> temp.asShort = yourIntValue;
>
> temp.asShort[0]; // lo byte or hi byte
>
>
> This technique is of course totally dependent on compiler and endiandness
> and compiler options, and thus is not portable.
>
> If the variable (temp above) is global, IIRC, SDCC produces decently
> effective code for above.
>
>
This approach requires two byte more RAM. Then bitwise operation or
((unsigned char *)&add)[0] method.

-- 
Cheers,
Grissiom
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to