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 it is amoral... (Re: When is a cast not a cast?) Message-ID: <2765@buengc.BU.EDU> Date: 4 May 89 19:27:58 GMT References: <2747@buengc.BU.EDU> <2763@buengc.BU.EDU> <1558@auspex.auspex.com> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 56 In article <1558@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes: > >Can you come up with a similar definition for the addition of two >pointers? As Gwyn said (and he thinks I rejected it, but I didn't, he should check out that I was referring to his statement, not mine...) "addition of two pointers is meaningless." Addition of 0xfffe and 0xfffe puts you over the top of a data segment and that's bogus. Add that, as I posted earlier today, I now see that the "scaling" of pointers isn't to be trusted, either, and this addition doesn't even do what it appears to do, whether that's what I want or not. Addition of two pointers? I'd never do it. Addition of two things that have pointer type? That I might do. float array[100] float *a1, *a2; float *diffa; struct gomessyourself brray[100]; struct gomessyourself *b1, *b2; /* ...Code setting the array values, and pointing a1, a2, and b1 into their respective arrays... */ dobedobedoo(array,brray,&a1,&a2,&b1); /* Want to align the pointer differences; how far apart are the a's ? */ diffa = a2 - a1; /* Bogus in normal C */ /* Now align the b's */ b2 = b1 + diffa; What does that do? It tries to add a float-pointer to a struct-ugly-pointer. Mismatch errors fill my screen with a phosphorescent radiance. And well they should. Normal C, however, allows this sort of thing by telling one to declare int diffa; and merrily arithmeticise. No warnings, no complaints, not even a bump in the great, grassy field of complacen-C.... Mind you, it's real nice to be able to do it this way, and if one couldn't, we'd all be screaming for it, but it feels the same as adding shorts, longs, and ints together haphazardly. --Blair "Okay, `long diffa'. There, you happy?"