precedence of && (was: precedence of ?:)

Maarten Litmaath maart at cs.vu.nl
Wed Sep 13 07:39:12 AEST 1989


gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
[... Must
	0 ? 0 : i = 0
be parsed as
	(0) ? (0) : (i=0)
or as
	(0 ? 0 : i) = 0
? ...]
\
\OOPS!  As Steve Emmerson was the first to point out to me, the correct
\way to parse expressions in C is to follow the formal grammar reduction
\rules, not rely on the precedence/associativity tables.  Because the
\left operand in an assignment expression cannot be a conditional
\expression (it is constrained to be a unary expression with lvalueness),
\there is no legal way to parse the example into the second form.  Thus
\I was mistaken, as were the compiler implementors who parsed it that
\way.  Perhaps they made the same mistake I just did.

Then how about the following, Doug?  "There is no legal way to parse..."

	0 && i = 0
-- 
C, the programming language that's the same |Maarten Litmaath @ VU Amsterdam:
         in all reference frames.           |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.lang.c mailing list