Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 beta 3/9/83; site callan.UUCP
Path: utzoo!watmath!clyde!floyd!harpo!seismo!hao!hplabs!intelca!proper!callan!geoff
From: geoff@callan.UUCP (Geoff Kuenning)
Newsgroups: net.unix-wizards
Subject: Re: read(fd, &y, sizeof(y)) portability
Message-ID: <127@callan.UUCP>
Date: Mon, 19-Mar-84 15:36:15 EST
Article-I.D.: callan.127
Posted: Mon Mar 19 15:36:15 1984
Date-Received: Thu, 22-Mar-84 01:17:06 EST
References: <17137@sri-arpa.UUCP>, <2564@rabbit.UUCP>
Organization: Callan Data Systems, Westlake Village, CA
Lines: 30

>	You are better off writing:
>
>		read (fd, (char *) &y, sizeof (y))
>
>	It makes a difference on some machines.

Actually, you are still non-portable if there is a possibility that the data
will be read on a machine different from the one it was written on.  Any of
the following problems might crop up:

	Character sizes differ (yes, there are still 6-, 7-, and 9-bit bytes
		out there--GCOS, for example, uses 9 bits)
	Long sizes differ (less likely but conceivable)
	Byte orderings differ

I ran into the last one trying to read the Bell distribution tapes on a
68000.  "cpio" writes the tape header with the type of construct suggested
above, but writes the tape contents in character form.  If I byte-swap the
contents appropriately, the header gets screwed up because of 68000/vax
byte ordering differences.  "cpio" has a switch ('-c') to solve this problem
by never writing binary data, but Bell (in their infinite wisdom) did not
use this option when writing their distribution tapes.

			 _ _ _ _ _ _ _
(Isn't every computer a |d|i|g|i|t|a|l| computer?)
			 - - - - - - -

			Geoff Kuenning
			Callan Data Systems
			...!ihnp4!sdcrdcf!trwrb!wlbr!callan!geoff