Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!mtune!codas!novavax!murphy!dave From: dave@murphy.UUCP (Dave Cornutt) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: pointer alignment when int != char * Message-ID: <588@murphy.UUCP> Date: Mon, 31-Aug-87 10:03:40 EDT Article-I.D.: murphy.588 Posted: Mon Aug 31 10:03:40 1987 Date-Received: Fri, 4-Sep-87 05:35:15 EDT References: <493@its63b.ed.ac.uk> <6061@brl-smoke.ARPA> <3812@spool.WISC.EDU> <7939@think.UUCP> Organization: Gould CSD, Fort Lauderdale, FL Lines: 46 Xref: mnetor comp.lang.c:4091 comp.unix.wizards:4006 In article <7939@think.UUCP>, barmar@think.COM (Barry Margolin) writes: > In article <572@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: > >In article <483@mtxinu.UUCP>, ed@mtxinu.UUCP (Ed Gould) writes: > > > >> It's also not legal in the proposed ANSI C standard. Pointers > >> may be subtracted *only* if they point to members of the same > >> array of elements. > > > > This is not an unnecessary restriction. It is there because the > construct is non-portable, and the purpose of the C standard (indeed, > ANY language standard) is to define a language in which portable > programs may be written. I'll agree that the construct posted, (long) p1 - (long) p2, is nonportable and should be flagged as such. However, I will say this, because I don't think the standard has really addressed it: there should be a way to take any pointer and generate a byte offset from byte 0 in whatever address space the code is running in. The reason is that you need such a beast to feed to lseek if you want to access something through one of the /dev/mem devices (or maybe /proc). > In fact, I know of an architecture where it may return different > results for pointers to the same two objects at different times: the > Symbolics Lisp Machine. It has a garbage collector that moves objects > around in memory, so the addresses may change, and therefore the > difference may change. I must be missing something here. Admittedly, I don't know anything about this machine, but it looks like this garbage collection would make pointers useless, since there is no guarantee that, when you dereference a pointer, the object that you're referring to will be in the same place that it was when you obtained the address. I can see how it could be done using some sort of highly segmented memory, but it seems like the overhead would be enormous (i.e., the iAPX 432). How does this work? --- "I dare you to play this record" -- Ebn-Ozn Dave Cornutt, Gould Computer Systems, Ft. Lauderdale, FL [Ignore header, mail to these addresses] UUCP: ...!{sun,pur-ee,brl-bmd,seismo,bcopen,rb-dc1}!gould!dcornutt or ...!{ucf-cs,allegra,codas,hcx1}!novavax!gould!dcornutt ARPA: dcornutt@gswd-vms.arpa "The opinions expressed herein are not necessarily those of my employer, not necessarily mine, and probably not necessary."