Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!mit-eddie!mit-amt!mit-caf!vlcek From: vlcek@mit-caf.MIT.EDU (Jim Vlcek) Newsgroups: comp.lang.c Subject: Addition of pointers Message-ID: <2299@mit-caf.MIT.EDU> Date: 7 May 89 02:17:49 GMT References: <2765@buengc.BU.EDU> <563@lzaz.ATT.COM> <4093@ficc.uu.net> Reply-To: vlcek@mit-caf.UUCP (Jim Vlcek) Organization: Microsystems Technology Laboratories, MIT Lines: 44 In article <4093@ficc.uu.net> peter@ficc.uu.net (Peter da Silva) writes: >In article <563@lzaz.ATT.COM>, hutch@lzaz.ATT.COM (R.HUTCHISON) writes: >> midpoint_pointer = (start_pointer + end_pointer) / 2; > >You're right. It's a valid operation. In what sense? It's invalid C, that's for sure. All you people who want to be able to add pointers, consider this: What is the significance of the sum of ``the location of Boston'' and ``the location of Detroit?'' Answer: none. Let's say you denote ``the location of Boston'' by it's longitude and latitude, and do likewise for Detroit. I'll denote these by L_B and L_D. Then you hack up a construct which purports to find the midpoint of the path joining Boston and Detroit: mid_point = (L_B + L_D)/2; Now, of course, one must define the division as well as the addition operator for the object ``location.'' So, you add up the longitudes and latitudes, and divide by two, right? Wrong, as anyone familiar with ``great circle'' navigation will recognize. My point here is that an abstract algebra has been defined for operations upon the objects which we call pointers, and there is no reason to assume that this algebra must be point-for-point analogous to the algebra of real numbers which we call arithmetic. Certainly one would not want to define, as part of this algebra, constructs such as ``location + location'' or ``pointer + pointer'' which in and off themselves do not have meaning. An operator which means ``midpoint'' _can_ be defined, of course; to attempt to denote it as (a+b)/2, however, is misleading in that it implies that the addition and division operators individually hold meaning. The concept of object types, and algebras working upon these types, should not be unfamiliar to software engineers. Although I am not myself a software engineer, I would think that one of the first, and most important, steps in the development of an application would be to define the objects used in the application and the operators which are applied to these objects, and then construct the algebra for these operators. Jim Vlcek (vlcek@caf.mit.edu uunet!mit-eddie!mit-caf!vlcek)