Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!saxony!dgil From: dgil@pa.reuter.COM (Dave Gillett) Newsgroups: comp.lang.c Subject: Re: Portability vs. Endianness Message-ID: <829@saxony.pa.reuter.COM> Date: 18 Mar 91 23:12:35 GMT References: <1991Mar12.105451.19488@dit.upm.es> <2628@ksr.com> Distribution: na Organization: Reuter:file Inc (A Reuter Company) Palo Alto, CA Lines: 17 In <2628@ksr.com> jfw@ksr.com (John F. Woods) writes: > Bytes[0] = (var >> 24) & 0xFF; > Bytes[1] = (var >> 16) & 0xFF; > Bytes[2] = (var >> 8) & 0xFF; > Bytes[3] = var & 0xFF; >This code is guaranteed. I don't think that the standard guarantees that chars are eight bits. I will agree that that's probably even more common than 4-byte longs, but even this assumption about word sizes cannot, IMHO, be guaranteed to be portable. (6-bit and 9-bit chars have gone out of style, but I've used machines with 16-bit word sizes that would *not* have produced the desired result for this code.) Dave