Addition of pointers

Jim Vlcek vlcek at mit-caf.MIT.EDU
Sun May 7 12:17:49 AEST 1989


In article <4093 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
>In article <563 at lzaz.ATT.COM>, hutch at 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 at caf.mit.edu  uunet!mit-eddie!mit-caf!vlcek)



More information about the Comp.lang.c mailing list