Portability vs. Endianness

esink at turia.dit.upm.es esink at turia.dit.upm.es
Tue Mar 12 20:54:51 AEST 1991


OK.  I read regularly, I check the FAQ List and other sources before
posting ANYTHING.  I even mail occasional simple questions directly
to someone with authority so I don't flood the net with a possible
FAQ.  However, the 'policing' on this group at times approaches
a neurotic level, so I proceed with caution.  Forgive me if this
has been discussed to death (FMITHBDTD)

Given the following :

long var;
unsigned char Bytes[4];


Is there a portable way to move the value held in var
into the memory space pointed to by Bytes, with the restriction
that the representation be in Most Significant Byte first
format ?  I am well aware that sizeof(long) may not be 4.  I
want the value contained in var converted to a 68000
long word, and I want the code fragment to run on any
machine.  The solution must be ANSI C.

Feel free to suggest your own declarations
to replace or augment mine.

Thanks in advance for the input,

Eric




Eric W. Sink                     | Putting the phrase      |All opinions
Departamento de Telematica       | "Frequently Asked"      |are mine and
Universidad Politecnica de Madrid| in your kill file is    |not necessarily
esink at turia.dit.upm.es           | not recommended.        |yours.



More information about the Comp.lang.c mailing list