Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!amgraf!cpsolv!rhg From: rhg@cpsolv.UUCP (Richard H. Gumpertz) Newsgroups: comp.lang.c Subject: Re: powerful expressions Message-ID: <462@cpsolv.UUCP> Date: 8 Dec 89 18:57:34 GMT References: <12855@cit-vax.Caltech.Edu> <24735@cup.portal.com> <5040@buengc.BU.EDU> Reply-To: rhg@cpsolv.uucp (Richard H. Gumpertz) Distribution: usa Organization: Computer Problem Solving, Leawood, Kansas Lines: 50 In article <5040@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >In article <24735@cup.portal.com> Tim_N_Roberts@cup.portal.com writes: >>In <12855@cit-vax.Caltech.Edu>, wen-king@cit-vax.Caltech.Edu (King Su) shares: >>> ((qhead) ? (qtail = qtail->next = qnew) >>> : (qtail = qhead = qnew))->next = 0; ... >Fear no more. > >The assignment operators group right-to-left. That is > > qtail->next = qnew > >is performed before > > qtail = qtail->next > >is performed. X3J11/88-158, page 10, line 22: "The grouping of an expression does not completely determine its evaluation." X3J11/88-158, page 39, line 5: "Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored." X3J11/88-158, page 53, line 30: "The side effect of updating the stored value of the left operand [of an assignment operator] shall occur between the previous and the next sequence point." X3J11/88-158, page 53, line 33: "The order of evaluation of the operands [of an assignment operator] is unspecified." Much as I would like to agree that the code is safe, I can't find anything in the standard that guarantees it. I think the standards committee may have (intentionally?) blown this one; can anyone prove me wrong? The following should always work (assuming NULL is defined by the appropriate #include): (qhead ? qtail->next = qnew : qhead = qnew), (qtail = qnew)->next = NULL; By the way, I would like to have written (qhead ? qtail->next : qhead) = qnew, (qtail = qnew)->next = NULL; but lvalues are converted to rvalues in this context so THIS WON'T WORK! -- =============================================================================== | Richard H. Gumpertz rhg%cpsolv@uunet.uu.NET -or- ...uunet!amgraf!cpsolv!rhg | | Computer Problem Solving, 8905 Mohawk Lane, Leawood, Kansas 66206-1749 | ===============================================================================