Preprocessor code to figure out endianness ?

Larry Jones scjones at thor.UUCP
Fri Sep 14 00:26:08 AEST 1990


In article <28803:Sep1221:34:1690 at kramden.acf.nyu.edu>, brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
> on the occasions when I need to know byte order, I use something like
> 
> int hilo_magic = 1212958796; char *hilo = (char *) &hilo_magic;
> 
> hilo[0]hilo[1] is "HL" on machines that place the high byte first and
> "LH" on others. It even works on sixteen-bit machines, provided the
> compiler reduces 1212958796 to 18508.

Gee, it doesn't seem to work at all on my IBM 3090....
----
Larry Jones                         UUCP: uunet!sdrc!thor!scjones
SDRC                                      scjones at thor.UUCP
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150-2789             AT&T: (513) 576-2070
I always have to help Dad establish the proper context. -- Calvin



More information about the Comp.lang.c mailing list