powerful expressions

Blair P. Houghton bph at buengc.BU.EDU
Fri Dec 8 03:37:51 AEST 1989


In article <24735 at cup.portal.com> Tim_N_Roberts at cup.portal.com writes:
>In <12855 at cit-vax.Caltech.Edu>, wen-king at cit-vax.Caltech.Edu (King Su) shares:
>>	((qhead) ? (qtail = qtail->next = qnew)
>>		 : (qtail = qhead       = qnew))->next = 0;
>
>I am truly sorry for the order-of-evaluation flood that I am surely about
>to bring down upon myself, but...
>
>Is this guaranteed to work?  Does ANSI require a sequence point in
>(qtail = qtail->next = qnew) so that it works?  I have always been
>hesitant to write something like that, because I felt that the compiler
>could reasonably be expected to assign qnew to qtail first and thereby
>screw up qtail->next.  Am I fearing needlessly?

Fear no more.

The assignment operators group right-to-left.  That is

	qtail->next = qnew

is performed before

	qtail = qtail->next

is performed.

				--Blair
				  "K&R I, p. 191, for
				   what that's worth..."



More information about the Comp.lang.c mailing list