syntax for unary assignment operators (was Re: C history question)
Tom Karzes
karzes at mfci.UUCP
Wed Sep 20 02:22:14 AEST 1989
In article <2562 at jhunix.HCF.JHU.EDU> ins_akaa at jhunix.UUCP (Ta06) writes:
->>A somewhat consistent but fairly bizarre syntax would be
->> x -=;
->The problem with this is that you would like it to have the same precedence
->as ++ and --. ...
-
-Why? We don't expect the regular += to have the same precedence as +...
Because all unary operators in C have the same precedence, which is higher
than the precedence of any binary or ternary operator (other than the primary
expression operators). Introducing a unary operator with lower precedence
than assignment would be a disgusting wart. Furthermore, it would make C
agonizing to parse. What would the rules be for deciding when to reduce
x-= as opposed to looking for some expression following it? Since you
naively think that binary -= should have higher precedence than unary -=,
it means that you'd always have to look beyond the -= to see if there's
something there that you can use as a second operand. So you wouldn't be
able to write x -= * 3 because this would be parsed as x -= (*3), but you
might be able to write x -= / 3 since / isn't a valid unary operator. The
whole thing it utterly absurd.
As for += not having the same precedence as +, what does that have to do with
anything? All binary assignment operators in C have the same precedence,
which is lower than the precedence of +.
More information about the Comp.lang.c
mailing list