[comp.lang.c] Operator precedence

karl@haddock.UUCP (Karl Heuer) (12/12/86)

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.