Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!purdue!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <2764@buengc.BU.EDU> Date: 4 May 89 19:11:24 GMT References: <2747@buengc.BU.EDU> <10191@smoke.BRL.MIL> <2759@buengc.BU.EDU> <1556@auspex.auspex.com> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 57 In article <1556@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes: > >>but I find it more than unsettling that a pointer offset can not be >>expressed and manipulated directly in the pointer type. > >Why? "pointer offsets", if by that you mean "the value of one pointer >relative to another", aren't the same sorts of objects as pointers. viz, char array[100]; char *a1, *a2; struct ohmigoditsgross brray[100]; struct ohmigoditsgross *b1, *b2; int diffa; /* ...code in here setting a1, a2, b1, b2 to what they really should be, within their respective arrays... */ /* How far apart are they? */ diffa = a2 - a1; /* So far so C. */ /* The others should be aligned. */ b2 = b1 + diffa; /* Did I just do that? */ I've been doing things like that for years and thinking I was getting away with the golden eggs. What I just did was add something that's _really_ a couple of bytes in virtual size as though it was hundreds of bytes... if I think of them as only indices, I'm fine. It's when I start thinking in terms of physical byte-slots, no matter how it's scaled, that my logical evaluator blows a rectifier. It seems that I can actually put a segment, a board, or an ethernet link in between elements array[33] and array[34], and I could still get that a1 = array + 33; a2 = array + 34; diffa = a2 - a1; and always expect diffa is exactly 1, even if the ethernet link separating elements 33 and 34 of array[] is a million miles long. I.e., scaling doesn't have to be constant. This is nasty, but it works, and I'll buy it. I'll stop trying to add pointers. --Blair "Even though I want to."