The irregularity of the ?: operator
Doug Gwyn
gwyn at smoke.brl.mil
Thu May 2 12:56:15 AEST 1991
In article <RICHARD.91Apr17193717 at euler.iesd.auc.dk> richard at iesd.auc.dk (Richard Flamsholt S0rensen) writes:
> According to the syntax,
> x == 0 ? c = 2 : c = 4;
> is illegal, because it is parsed as
> (x == 0 ? c = 2 : c) = 4;
> Everyone (well, almost - otherwise there wouldn't be any discussions
>here on c.l.c :-) has acknowlegded, that this is correct.
Then "everyone" is wrong.
The LHS of an assignment expression must be a unary expression;
thus, your suggested parse is incorrect.
The example is unparsable according to the official C grammar.
By judicious addition of parentheses you could make it parse in
at least four distinct ways.
More information about the Comp.lang.c
mailing list