Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!chinet!dag From: dag@chinet.UUCP (Daniel A. Glasser) Newsgroups: comp.lang.c Subject: Re: C machine Message-ID: <2155@chinet.UUCP> Date: 29 Jan 88 06:39:27 GMT References: <461@auvax.UUCP> <28700025@ccvaxa> <7159@brl-smoke.ARPA> <8728@ism780c.UUCP> Reply-To: dag@chinet.UUCP (Daniel A. Glasser) Organization: Chinet - Public Access Unix Lines: 50 In article <8728@ism780c.UUCP> marv@ism780.UUCP (Marvin Rubenstein) writes: > [stuff deleted] > >BTW, the definition of pointer difference in K&R is "if p and q point to >members of the same array , p-q is the number of elements between p and q." > >One way to interpret this is the following: > > el1 el2 el3 > ^ ^ > | | > p q > >As can be seen from the diagram the number of elements "between" p and q is >1 (not 2). Furthermore, the number of elements between p and q is clearly >the same as the number of elements between q and p. i.e, p-q == q-p and no >overflow is possible. I hope the defininition in the proposed standard is >less ambigious than the wording in K&R. > I think you misinterpret the meaning of where things point to. The correct diagram for this would be +-----+-----+-----+----- You see, this is not ambiguous at | el1 | el2 | el3 | ... all -- there are exactly two elements +-----+-----+-----+----- between the addresses pointed to by ^ ^ p and q. | | p q This is a common mistake for novice programmers and HLL programmers who are not familiar with pointers to make. Pointers genereally contain the address where the "pointed to" item begins, not the item itself. When I was tutoring in college, one of the professors overdid the "mailbox" analogy, and a number of students believed that the computer must have different sized "boxes" for different kinds of data... So integer boxes were addressed the same as float boxes, just in a different part of memory. "I have a program that the Fortran compiler says has too much integer data. I'm not using any reals, so can I use the real storage for integers?" (I actually got that question!) I find that Basic programmers make this error most often. -- Nobody at the place where I work Daniel A. Glasser knows anything about my opinions ...!ihnp4!chinet!dag my postings, or me for that matter! ...!ihnp4!mwc!dag ...!ihnp4!mwc!gorgon!dag One of those things that goes "BUMP!!! (ouch!)" in the night.