Topic: Precedence of exponentiation operator
Author: matt@physics.berkeley.edu (Matt Austern)
Date: 20 Jul 92 11:23:56 Raw View
A while ago, I was arguing that the C++ exponentiation operator
should, to preserve ordinary mathematical meaning (and to preserve the
semantics of exponentiation in FORTRAN), have a higher precedence than
unary plus and minus. I now realize that I was mistaken; it is
impossible to do this without badly breaking something.
Unary + and - have the same precedence as unary * and &. We certainly
don't want an exponentiation operator to have a higher precedence than
those, and, of course, we can't break existing code by changing the
precedence of unary + and -. There is no choice but to say that
exponentiation has a higher precedence than *, /, and %, but a lower
precedence than the unary operators.
It is clear to me that this is the wrong precedence, but, well, it's
just a minor blemish, and it is not the only blemish in the C/C++
precedence table, and compilers can issue warnings when it looks like
users are doing the wrong thing. Some flaws you just have to live
with.
--
Matthew Austern I dreamt I was being followed by a roving band of
(510) 644-2618 of young Republicans, all wearing the same suit,
matt@physics.berkeley.edu taunting me and shouting, "Politically correct
austern@theorm.lbl.gov multiculturist scum!"... They were going to make
austern@lbl.bitnet me kiss Jesse Helms's picture when I woke up.
Author: ark@alice.att.com (Andrew Koenig)
Date: 21 Jul 92 02:41:58 GMT Raw View
In article <MATT.92Jul20112356@physics.berkeley.edu> matt@physics.berkeley.edu writes:
> There is no choice but to say that
> exponentiation has a higher precedence than *, /, and %, but a lower
> precedence than the unary operators.
Hm... Why couldn't it have the same precedence as -> and . ?
--
--Andrew Koenig
ark@europa.att.com