Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: pointer alignment when int != char * Message-ID: <7939@think.UUCP> Date: Sat, 29-Aug-87 17:18:21 EDT Article-I.D.: think.7939 Posted: Sat Aug 29 17:18:21 1987 Date-Received: Sun, 30-Aug-87 09:19:51 EDT References: <493@its63b.ed.ac.uk> <6061@brl-smoke.ARPA> <3812@spool.WISC.EDU> <483@mtxinu.UUCP> <572@l.cc.purdue.edu> Sender: news@think.UUCP Reply-To: barmar@godot.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 37 Xref: mnetor comp.lang.c:4032 comp.unix.wizards:3975 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. > >The fact that some `gurus' cannot see the uses of this construct, as well >as others such as goto's, forcing inline, etc., is no more appropriate >than prohibiting the use of any tools developed since 1800 to sculptors. >You have no way of knowing how I can use the power of the machine; I may >very well find a new way of doing some things tomorrow that I do not see >today. Let us remove unnecessary restrictions from the languages. 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. No one is prohibiting you from subtracting pointers to your heart's delight on machines where it makes sense; just be aware that the standard doesn't specify what the result will be, so your program may behave differently on different architectures. 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. (Note: I've never used their C compiler, so I don't know it will do this; however, I also believe that their architecture allows them to detect comparisons of pointers to different arrays). --- Barry Margolin Thinking Machines Corp. barmar@think.com seismo!ththers' arta