Portability vs. Endianness

Doug Gwyn gwyn at smoke.brl.mil
Thu Mar 21 07:09:49 AEST 1991


In article <829 at saxony.pa.reuter.COM> dgil at pa.reuter.COM (Dave Gillett) writes:
>>	Bytes[0] = (var >> 24) & 0xFF;
>>	Bytes[1] = (var >> 16) & 0xFF;
>>	Bytes[2] = (var >> 8)  & 0xFF;
>>	Bytes[3] =  var        & 0xFF;
>     I don't think that the standard guarantees that chars are eight bits.

It does guarantee that they can hold AT LEAST 8 bits.
Assuming sufficient care is taken with use of unsigned types, etc.,
that is not a problem.
However, as mentioned before, the failure to consider representation
issues for negative values can be a problem, depending on the implementation.



More information about the Comp.lang.c mailing list