"Dik T. Winter" <> writes:
> In article <> Keith Thompson
> <kst-> writes:
> ...
> > Speaking as a long-time Ada programmer, I don't recall my head
> > exploding when I learned this. The explanation is perfectly clear,
> > but the rule is a bit silly. Nothing would have been lost by allowing
> > pointer+integer and forbidding integer+pointer.
> >
> > I suppose it goes back to the days when C didn't make such a strong
> > distinction between pointers and integers.
>
> No, it goes back to the days when operators like "+" where commutative.
Yes, when it denotes addition of numbers.
The "+" operator is usually commutative, but it usually takes two
operands of the same type. Commutativity makes less sense when the
operands are of different types.
Some languages use "+" to denote string catenation; in such a
language, "foo" + "bar" doesn't mean the same thing as "bar" + "foo".
In my opinion (and it's nothing more than that), the C language would
be cleaner if pointer+integer were allowed (as it is now) and
integer+pointer were disallowed (making index[array] illegal). I'm
not proposing that it should be changed now, since it would break
existing code. Allowing integer+pointer isn't particularly harmful,
but I don't think it's necessary.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.