Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!rutgers!mtune!codas!cpsc6a!rtech!wrs!dg
From: dg@wrs.UUCP (David Goodenough)
Newsgroups: comp.lang.c
Subject: Re: Writing readable code
Message-ID: <278@wrs.UUCP>
Date: Mon, 27-Jul-87 19:29:12 EDT
Article-I.D.: wrs.278
Posted: Mon Jul 27 19:29:12 1987
Date-Received: Wed, 29-Jul-87 05:40:30 EDT
References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <840@mcgill-vision.UUCP> <1126@nu3b2.UUCP>
Reply-To: dg@wrs.UUCP (David Goodenough)
Organization: Wind River Systems, Emeryville, CA
Lines: 29

In article <1126@nu3b2.UUCP> rwhite@nu3b2.UUCP (Robert C. White Jr.) writes:
>In article <840@mcgill-vision.UUCP>, mouse@mcgill-vision.UUCP (der Mouse) writes:
>> The difference becomes significant if you ever take the address of c.
>> For example,
>> 
>> 	write(fd,&c,1);
>> 
>> takes on an entirely different meaning.  If c is a char, this is
>> portable (provided sizeof(char)==1 -- are there any machines on which
>> this is not true?), but if c is an int you get what you probably expect
>> on a little-endian and it breaks mysteriously on a big-endian.
>
>	Oddly enough, by definition what you have used above is a valid
>construct on just about every machine I have ever seen. .....

Since the NUXI problem exists (byte order between DEC & IBM) exactly
one of the architectures will fail - in addition motorola 6800's will fail
as will 6809's, both of these put high byte first, and the 68K will fail:
in a 4 byte int the bytes are stored highest first, lowest last. On the
rare occasions I use write(fd, &c, 1) (terminal output only) I *ALWAYS*
declare c as a char - it is the only safe portable way to do it (If anyone
disagrees I've got my asbestos suit ready :-)
--
		dg@wrs.UUCP - David Goodenough

					+---+
					| +-+-+
					+-+-+ |
					  +---+