Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!linus!philabs!cmcl2!seismo!harvard!talcott!panda!genrad!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: c programming style Message-ID: <2461@sun.uucp> Date: Sun, 21-Jul-85 17:45:25 EDT Article-I.D.: sun.2461 Posted: Sun Jul 21 17:45:25 1985 Date-Received: Wed, 24-Jul-85 06:28:28 EDT References: <13@brl-tgr.ARPA> <1303@uwmacc.UUCP> Organization: Sun Microsystems, Inc. Lines: 32 > I submit that equating a globally recognized set of constants (i.e. the > set of integers) with values that differ depending on whatever program > variable happens to be nearest to them is guaranteed to be misleading. What changed is not the values of the integers but the operation implied by the "+" operator. pointer + N causes the pointer to point to the object (of the type the pointer's type is derived from) N objects (*NOT* N machine storage units) further into the array that "pointer" is assumed to point to a member of. This is a bit subtle, but a lot easier to understand if you realize that pointers are NOT integers but abstract cookies referring to objects in memory. Most of the confusion stems from a too low-level mental model of C; people think of pointers as integers indexing a memory considered as a sequence of machine storage units instead of as the aforementioned abstract cookies. The fact that so many people have trouble with this is either because: 1) The low-level model of memory and pointers is so ingrained into programmer's consciousnesses that trying to make pointers a more abstract model is doomed to failure or 2) C just hasn't been taught correctly - the instruction gives a lower-level model than is appropriate. The solution to 1) is to rip out pointer arithmetic, use arrays instead, and have all C compilers do strength reduction to generate multiplication-free code. The solution to 2) is to avoid giving the impression that C is a structured assembly language. Guy Harris