E
Eric Sosman
Richard said:If I take a tape measure and put the end at some arbitrary distance
away, and measure the position of two points (along the line of the
measure) with it, then I can find the average position by adding the
measurements and dividing by two, and I will get the same answer
regardless of where the end of the measure is. Similarly, it works
perfectly well to add two temperatures in Fahrenheit and divide by two
to get the average, and it also works perfectly well in Celsius and
Kelvin, and you get the same answer whichever you use.
If a scale has some kind of zero offset, then of course the sum of two
values will have two of those offsets in it, but provided the meaning
you ascribe to the sum requires you to subtract off a value of the
same kind, or divide by two, before interpreting it on the original
scale, it will all cancel out.
The sum of two pointers doesn't make sense *as a pointer* any more
than the sum of two Fahrenheit temperatures makes sense as a
Fahrenheit temperature. But that doesn't mean it doesn't make sense
at all.
In an object-oriented language you could define a type "sum of two
pointers", whose constructor takes two pointers. Then you could
defined methods on the type such as subtraction of a pointer, which
would return a pointer.
Ah, I now see where you're heading. The choice of a zero
still presents a problem, though, because of possible overflow.
The "sum of pointers" object would need to be wider than the
summed pointers themselves, else the averaging you mention could
fail spectacularly (add two pointers to an object "near the top
of memory," lose the high-order bit of the sum to overflow, divide
by two, and you've got a pointer to someplace in "the bottom half
of memory," not even close to the original target object).
Another problem: If a "sum of two pointers" data type were
defined, somebody would come along and ask for a "sum of N
pointers" object, whose characteristics would be unlike those of
the two-pointer sum (e.g., dividing by 2 gives garbage, while
dividing by N makes sense; you must subtract N-1 pointers from
it rather than just one to retrieve an ordinary pointer, etc.).
And *then* someone will start asking how to calculate the standard
deviation of a population of pointer values ...
It might be possible to cook up such an extension, but I
think it would be, er, in poor taste.