Precedence Question - (nf)

mather at uicsl.UUCP mather at uicsl.UUCP
Sun Feb 12 13:46:08 AEST 1984


#R:smu:13800001:uicsl:6400012:000:876
uicsl!mather    Feb 10 14:13:00 1984

>Is	cat = foo ? fu = bar : mouse;	legal?
>
>	legal 'according to K & R ..."?

Well obviously it is legal. The question is:
is bar assigned to fu before the result of ?: is assigned to cat?

Perhaps this question has deeper undertones than I can perceive, but
my understanding of precedence and order of evaluation was ?: (as a
unit) had a higher order of precedence than = so that 'cat' gets the
value of 'bar' or 'mouse' depending on the value of 'foo', rather than
assigning 'cat' to 'foo'. But that's not what's happening. 'foo' is
evaluated, if true, e2 (fu = bar) is evaluated and assigned to 'cat'.
'mouse' is left alone. If foo is 0 (false), then 'mouse' is evaluated and
assigned to 'cat'. 'fu' is never set to 'bar' in this case.
(K&R top of p48).

foo		is e1		in  e1 ? e2 : e3
fu = bar	is e2
mouse		is e3

					B.C.Mather
					Le Maitre
					...uiucdcs!uicsl!mather



More information about the Comp.lang.c mailing list