Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!ames!lll-lcc!lll-winken!uunet!mcvax!hp4nl!philapd!ssp1!roelof From: roelof@idca.tds.PHILIPS.nl (R. Vuurboom) Newsgroups: comp.lang.c Subject: Re: Adding two pointers Summary: Nonstandard arithmetic Message-ID: <113@ssp1.idca.tds.philips.nl> Date: 8 May 89 14:39:15 GMT References: <2765@buengc.BU.EDU> <563@lzaz.ATT.COM> <4093@ficc.uu.net> <922@garcon.cso.uiuc.edu> <924@garcon.cso.uiuc.edu> Organization: Philips Telecommunication and Data Systems, The Netherlands Lines: 56 In article <924@garcon.cso.uiuc.edu> mcdaniel@uicsrd.csrd.uiuc.edu (Tim McDaniel) writes: >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). > Perhaps more of a mathematical nature. > [Gives argument showing that if addition is added an equation can result that has different types...] The properties stated result in fact from some basic properties present in arithmetic models: fields. (These models model our arithmetic or arithmetic is based on these models - take your pick). These properties include (math books everyone!) associativity, closure, inverseness (having an inverse),distribution and a null element and other pleasant niceties . Lets assume pointer addition (new style). There seems to be a consensus that this should result in a pointer type. In other words: P + Q = R (where P,Q,R are pointer types) also M + n = P ( where M,P are pointer types, n is an integer) ^ Now a little operator overloading is going on here. The first + and the second + are conceptually different operators. So lets use '+' for the 2nd operator. Thus M '+' n = P This is something akin to scalar multiplication of vectors. Now in "standard" arithmetic models the operation '+' would have to support distribution i.e. n '+' (P+Q) = (n'+'P) + (n'+'Q) Just as 3(a+b) = 3a + 3b. However the semantics we seem to be aiming for is: n '+' (P+Q) = (n'+'P) + Q = P + (n'+'Q) Now this is going to result in a "nonstandard" model with any number of (for us) strange arithmetic properties. (Left as exercise to the reader :-). Now theres nothing intrinsically wrong with nonstandard arithmetic models. However the makers of C in their infinite wisdom (naive innocence?) were probably just trying to model standard arithmetic. Which I think is as it should be. Introducing pointer addition with the above semantics would have introduced nonstandard arithmetic into the language. Disclaimer: Opinions are my own, for my employers you pay extra.