Preprocessor code to figure out endianness ?

John Keck keck at sea.com
Sun Sep 16 06:22:56 AEST 1990


In article <28803:Sep1221:34:1690 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
> [...]
>
>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.
>
>---Dan

As long as they use the ASCII character set.


-- 
John Keck INTERNET:keck at sea.com UUCP:...!ucsd!soledad!keck VOICE:619/581-6181
Systems Engineering Associates, 2204 Garnet Ave Suite 203, San Diego CA 92109
-----------------------------------------------------------------------------
 "Much speech leads inevitably to silence. Better to hold fast to the void."



More information about the Comp.lang.c mailing list