Byte order (retitled)

greg at utcsri greg at utcsri
Sat Apr 26 15:59:00 AEST 1986


In article <1117 at psivax.UUCP> friesen at psivax.UUCP (Stanley Friesen) writes:
>In article <2590 at utcsri.UUCP> greg at utcsri.UUCP (Gregory Smith) writes:
>>...
>	And I am saying that the following *should* be portable, and
>that any implementation that it doesn't work on is brain-damaged.
>
>	register int i;
>	unsigned char bytes[ sizeof( long )];		/* lo-byte first */
>	long input;
>	register char *cvptr;
>
>	for(cvptr = (char *)&input, i = 0; i < sizeof(long); i++)
>		bytes[i] = cvptr[i];
>
Sorry - I thought you were suggesting that big-endian pointer conversions
should set the lower bits (when pointing to a smaller object) and clear
them (when pointing to a larger one). What you are actually saying is
that any implementation which is not strictly little-endian is 'brain-
damaged' (Including (a) PDP11 _longs_, (b) 68000). I will agree that (a)
is brain-damaged, but I think the adjective is a little strong for (b).
I am a little-end fan myself, but I can face reality, and the reality is
there will be big-endian machines around that are still worth using, and
that the 'problem' can be dealt with so easily that one needn't damn
the 68K to eternal flames on this one point.

-- 
"For every action there is an equal and opposite malfunction"
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg



More information about the Comp.lang.c mailing list