Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!garcon!uicsrd.csrd.uiuc.edu!mcdaniel From: mcdaniel@uicsrd.csrd.uiuc.edu (Tim McDaniel) Newsgroups: comp.lang.c Subject: Re: Adding two pointers Summary: 2 of clubs + 7 of clubs == a two-card hand Message-ID: <924@garcon.cso.uiuc.edu> Date: 7 May 89 04:29:52 GMT References: <2765@buengc.BU.EDU> <563@lzaz.ATT.COM> <4093@ficc.uu.net> <922@garcon.cso.uiuc.edu> Sender: news@garcon.cso.uiuc.edu Reply-To: mcdaniel@uicsrd.csrd.uiuc.edu (Tim McDaniel) Organization: Center for Supercomputing R&D (Cedar), U. of Ill. Lines: 48 I've thought of one more argument against pointer addition in C. It is of a more philosophical nature (and thus I grant that it's not as strong as my previous ones). There are a lot of arithmetic identities that are handy to have around. Granted that some don't hold, even with the comparatively- tame integers excluding overflow. For example, you can't make all of the div/mod identities true simultaneously for integers: a%b + a/b == a 0 <= a%b and a%b < abs(b) (-a)/b == a/(-b) == -(a/b) However, one identity that holds (excluding overflow for signed integers) is a + b == c if and only if a == c - b Suppose addition of pointers gives a pointer, such that a + b == c However, a == c - b is erroneous from a type point of view -- the right-hand side is an integer in C, but the left-hand side is a pointer. Since pointer subtraction yields an integer in C, its inverse operation is the addition of a pointer to an integer. (If you want to design a language in which pointer subtraction somehow yields another pointer, go right ahead, but I'll never program in it, and it's not compatable with C.) To use the "deck of cards" analogy: in C, the difference between the 9 of clubs and the 7 of clubs is 2. Not "2 of clubs" -- just plain 2. As a friend just pointed out (thanks, Paul!), adding the 2 of clubs to the 7 of clubs just gives you a two-card hand. You *can't* add cards. :-) Pointers are not cards. Pointers do not have units like "feet". Any analogies may work, or they may not -- no guarantees. -- Tim, the Bizarre and Oddly-Dressed Enchanter Center for ||| Internet, BITNET: mcdaniel@uicsrd.csrd.uiuc.edu Supercomputing ||| UUCP: {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel Research and ||| ARPANET: mcdaniel%uicsrd@uxc.cso.uiuc.edu Development, ||| CSNET: mcdaniel%uicsrd@uiuc.csnet U of Illinois ||| DECnet: GARCON::"mcdaniel@uicsrd.csrd.uiuc.edu"