Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!rutgers!sri-unix!sri-spam!ames!sdcsvax!ucsdhub!jack!man!nu3b2!rwhite
From: rwhite@nu3b2.UUCP (Robert C. White Jr.)
Newsgroups: comp.lang.c
Subject: Re: Writing readable code
Message-ID: <1126@nu3b2.UUCP>
Date: Fri, 24-Jul-87 21:37:24 EDT
Article-I.D.: nu3b2.1126
Posted: Fri Jul 24 21:37:24 1987
Date-Received: Sun, 26-Jul-87 00:54:20 EDT
References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <840@mcgill-vision.UUCP>
Organization: National University, San Diego
Lines: 48
Summary: OK, but really...

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 low
order byte of a word, and the low order word of a double-word are stored
"above" the high-order portion you get:

		+--------+--------+
		| low    | high   |
		+--------+--------+
		    ^
		    |
		This is the point indicated by the address-of operator
and if char is the size of int, it does not matter.  If char is a byte
and int is a word, the low order bits of the int corrispond to the
byte that would be union aligned of type char [etc].  By the definition
your code fragment WILL work [i.e. produce the correct result] wether
c is int or char.  [which is why the spec. tells you to use int]
	On any machines which do not use this inter-position, the use
of pointers is massaged in the memory model to produce the same net
effect.  If this arangement, or some adaptive work-around were not
built into the language, the casting between types [i.e. assigning
the value of a sufficiently small int to a char] would produce more
logical shifting and adaptive work than the actual math/assignment.
 int x; char y; x = 13 ; y = x;  would be unreasonably large.
	The only real problem comes down to potiner MATH, but as long
as aray of int/char are used consistantly that wont matter either.

	If you dont believe me, get out your DDT and take a look.
	If I am wrong..... SUE ME!


Robert.

Disclaimer:  My mind is so fragmented by random excursions into a
	wilderness of abstractions and incipient ideas that the
	practical purposes of the moment are often submerged in
	my consciousness and I don't know what I'm doing.
		[my employers certainly have no idea]