precedence of ?: (was: precedence of && (was: precedence of ?:))
Doug Gwyn
gwyn at smoke.BRL.MIL
Fri Sep 15 07:44:32 AEST 1989
In article <3260 at solo5.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>[... 0 ? 0 : i = 0
>is accepted, whereas
> 0 && i = 0
>is not.]
>But why allow the `?:' expression, why make it a special case?
I was mistaken in my original response; 0 ? 0 : i = 0 is not legal.
However, to save another iteration in this series of postings, note
that 0 ? i = 0 : 0 is legal.
conditional-expression:
logical-OR-expression
logical-OR-expression ? expression : conditional-expression
So the interesting question becomes, why is that "expression" for the
second operand of ?: and not "logical-OR-expression". (I think that
"conditional-expression" might result in ambiguity.) The Rationale
says merely that "several extant implementations have adopted this
practice". That must be the answer..
More information about the Comp.lang.c
mailing list