Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!nbires!hao!hplabs!pesnta!wjvax!brett From: brett@wjvax.UUCP (Brett Galloway) Newsgroups: comp.lang.c Subject: Re: Is an object made up of bytes? Message-ID: <812@wjvax.wjvax.UUCP> Date: Wed, 21-Jan-87 12:30:11 EST Article-I.D.: wjvax.812 Posted: Wed Jan 21 12:30:11 1987 Date-Received: Fri, 23-Jan-87 00:47:21 EST References: <2144@brl-adm.ARPA> <5497@brl-smoke.ARPA> <5527@brl-smoke.ARPA> <5536@brl-smoke.ARPA> Reply-To: brett@wjvax.UUCP (Brett Galloway) Organization: Watkins-Johnson Co., San Jose, Calif. Lines: 34 In article <5536@brl-smoke.ARPA> gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: >> The semantics of "(char *) &object" aren't guaranteed to produce anything >> that can be safely dereferenced to access a char. >> ... there may be "big endian" byte-addressed architectures where the >> numeric address of a word is not the lowest-valued address of the bytes >> within the word ... > >I occurs to me that X3J11 needs to add a guarantee that at least a cast >to (void *) results in something representing the lowest-valued address >of any byte in the object pointed at by whatever pointer is being >converted; otherwise what good are the mem*() functions? > >Some of the issues raised by RMS are deeper than I at first realized. I agree. It seems odd, though, that (void *) and (char *) would behave differently. I know that there is a lot of existing code that assumes that (char *) behaves this way. This assumption is necessary because (void *) doesn't exist, and bcopy (or memc?py) on (char *)&foo is too useful. Another example is writing data to a file -- how could one ever write anything but a character string to a file? For example, to write an object short foo; to a file, one must do something like fwrite((char *)&foo,sizeof(short),1,file) at least in 4.2BSD. In order to maintain this ability, it must be possible to obtain the "numeric address of an object which is the lowest-valued address of the bytes within the object." One could make (void *) this object, but that is still not correct -- fwrite needs to dereference the pointer to the object to get characters, not "voids". I suppose one could do (char *)(void *)(&foo), but that is ugly. -- ------------- Brett Galloway {pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett