karthikbalaguru <(E-Mail Removed)> writes:

> If they are able to support addition & subtraction, but why

> haven't they supported multiplication or division of a pointer ?

> Any difficulty in supporting those functionalities ?
There's a difficulty of definition. Let's start with the pointer

arithmetic that we /can/ do:

* we can add integers to (and subtract them from) pointers; and

* we can subtract one pointer from another (sometimes).

This addition fails to be associative, however:

p + (q - r)

is well-defined (if p, q, r are pointers, and q and r are within or

one-past-the-end of the same object), but

(p + q) - r

is meaningless. Note also that there is no such thing as an additive

inverse for pointers: although p - p = 0 for all (valid) pointers to

objects, the notation -p is not meaningful.

(Aside: is there a name for this kind of algebraic structure? I

wouldn't be at all surprised if it weren't considered interesting enough

to have a name, but it'd be nice to know for sure.

)

So, what kind of multiplication do we want? To be useful, a

multiplication ought to be distributive over addition, and 1 ought to be

a scalar-multiplicative identity, so

2*p = (1 + 1)*p = 1*p + 1*p = p + p

which is still without meaning. So that's out.

What about multiplying two pointers? Umm, well:

(p + 2)*q = p*q + 2*q

but we've already decided that 2*q wasn't meaningful. So that's out.

As for division, let's get multiplication sorted first, shall we?

-- [mdw]