Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!apple!julius.cs.uiuc.edu!wuarchive!udel!haven!adm!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: Preprocessor code to figure out endianness ? Message-ID: <28803:Sep1221:34:1690@kramden.acf.nyu.edu> Date: 12 Sep 90 21:34:16 GMT References: Organization: IR Lines: 16 In article otto@tukki.jyu.fi (Otto J. Makela) writes: > I seem to remember seeing somewhere a real smart preprocessor construction > to figure out the endianness of the machine under which the code was being > compiled. I cannot remember where and how, though ? Any pointers ? I don't know about this. I can never remember whether people mean ``big-endian'' as high-low or low-high; 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. ---Dan