Expression sequencing query

Pedz Thing pedz at bobkat.UUCP
Wed Oct 1 02:17:46 AEST 1986


In article <673 at galbp.UUCP> gbm at galbp.UUCP (Gary McKenney) writes:
>> In article <760 at oakhill.UUCP> tomc at oakhill.UUCP (Tom Cunningham) writes:
>> >	/* a = b + b + b */
>> >	a = ((b=1),b) + ((b=2),b) + ((b=3),b)
>> >

Lets change the expression from
	a = ((b=1),b) + ((b=2),b) + ((b=3),b)
to
	a = ((a1),r1) + ((a2),r2) + ((a3),r3)

Where a1 stands for assignment (to b) 1 and r1 stands for reference
(to b) 1.  The following conditions must be meet for proper code:
a1 before r1
a2 before r2
a3 before r3

That is all of the restrictions imposed by C.  Thus the following is
correct code:

a3, a2, a1, r1, r2, r3

which produces the answer of 3.  I think I can come up with correct
code which produces an answer anywhere form 3 to 9.

This same question comes up every few days it seems like.  I do not
see what is so confusing about it.  The simple law that C imposes no
restrictions on the ordering of most operators never seems to be
understood.

Perry
-- 
Perry Smith
ctvax ---\
megamax --- bobkat!pedz
pollux---/



More information about the Comp.lang.c mailing list