Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!oliveb!3comvax!bridge2!jzs From: jzs@bridge2.ESD.3Com.Com (Jeremy A. Siegel) Newsgroups: comp.lang.c Subject: Re: When it is amoral... (Re: When is a cast not a cast?) Message-ID: <615@bridge2.ESD.3Com.Com> Date: 10 May 89 02:34:00 GMT References: <2747@buengc.BU.EDU> <2763@buengc.BU.EDU> <5779@xyzzy.UUCP> <2805@buengc.BU.EDU> Reply-To: jzs@bridge2.3Com.com (Jeremy A. Siegel) Organization: 3Com Corp., Mt. View, CA Lines: 50 >>The point is, Blair expects an object defined as one type to behave both >>as if it were a pointer and an offset at the same time. This is NOT sensible. >Nay, I want it to behave as an object, and not as some nebulous changeling ^^ ^^^^^^^^^ >requiring maintenance-by-fiat. If one is yea-big and the other is yo-big, >then I damn well want the difference between them to be yea-yo, at the >very least when I _tell_ it to be so. My, my! I'd nearly stopped reading this thread; it seems to have generated so much theoretical discussion (pun(?) intended). But I just had to try on this one... There is no such thing as "a pointer" -- the pointer (*) syntax is a *constructor*, producing a new and exciting object each time it is used! That is, there is one type "pointer to char" which is ALWAYS a certain size, and which always behaves exactly the same under the defined arithmetic operations... there's another type "pointer to long" that is also self-consistent: but it admittedly does not behave the same as a "pointer to char", and there's no reason why it should. (Are the two arrays (int a1[10]) and (int a2[5]) the same size?) It really is important that pointers and offsets not be confused; it is also important that offsets and integers not be confused -- even though they're kind of the same. (I'm not really sure what I mean by that, except that an integer -- e.g. 5 -- when used in an operation with a pointer should not be viewed as an integer but as an offset, which has "units"; that is, not "five" but "five of those"). As people have said here already, don't think of a pointer as a certain bit-pattern, and incrementing like integer addition. (Get a hold of a PDP-10, or it's assembly manual, and look at byte pointers instructions to modify them -- it'll cure you in a hurry.) Rather than agree/disagree on the merits of earlier arguments presented, how about a plea for peace: there was a statement about pointers not having "units". Let's pretend they do, but we don't know what to call them -- and that you certainly can add to pointers but the thing you get is different units, and there's no other operations defined on them, so who care? (Maybe look at pointers as logs? I can add and subtract them and I know how to use the result for multiplication and division. I can also mulitply them, but I don't know what to do with the result. [Note the *I*, not *you*, since there's sure to be some *you* out there just dying to explain about products of logarithms. Direct those followups to sci.math where I won't have to read them :-] ) --Jeremy Siegel 3Com Corp. Mountain View