Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!lll-crg!ames!ucbcad!ucbvax!decvax!ima!haddock!karl
From: karl@haddock.UUCP (Karl Heuer)
Newsgroups: comp.lang.c
Subject: Operator precedence (was: incrementing after a cast)
Message-ID: <192@haddock.UUCP>
Date: Thu, 11-Dec-86 23:23:25 EST
Article-I.D.: haddock.192
Posted: Thu Dec 11 23:23:25 1986
Date-Received: Sun, 14-Dec-86 16:33:06 EST
References: <349@apple.UUCP> <2319@mtgzz.UUCP> <4674@mimsy.UUCP> <4691@mimsy.UUCP>
Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer)
Distribution: net
Organization: Interactive Systems, Boston
Lines: 23
Summary: New way to say it (simpler, I think)

In article <4691@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>In article <4674@mimsy.UUCP>, in reference to `L = *((int *)cp)++', I wrote:
>>casts and `++' have higher precedence than `*'.
>[Correcting himself]  Casts, ++, and unary * all have the same precedence;
>but they group right-to-left, not left-to-right.

The usual terminology is that the unary operators are "right-associative",
but I dislike this.  (Associativity, to me, only makes sense for binary ops.)
I prefer to rephrase the rules as follows (keeping the same semantics):

The postfix unary operators have highest priority, then the prefix unaries,
then the various binary operators.

The postfix operators are "(arglist)", "[expr]", ".member", "->member", "++",
and "--".  Since there is only one way to parse an expression with two postfix
ops, it doesn't make sense to say "they all have the same precedence".

The prefix operators are "(type)", "~", etc.  Again, there's no need to talk
about precedence or associativity.  You can't even ask that question.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
Please do not followup to say "but `[]', etc are called `primary ops', not
`postfix unary'".  I know that!  I claim my rephrase is equivalent.