Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: powerful expressions Summary: My bad. Message-ID: <5048@buengc.BU.EDU> Date: 9 Dec 89 16:34:56 GMT References: <12855@cit-vax.Caltech.Edu> <24735@cup.portal.com> <5040@buengc.BU.EDU> <462@cpsolv.UUCP> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Distribution: usa Organization: Boston Univ. Col. of Eng. Lines: 57 In article <462@cpsolv.UUCP> rhg@cpsolv.uucp (Richard H. Gumpertz) writes: >In article <5040@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) 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; >... >>The assignment operators group right-to-left. That is >> qtail->next = qnew >>is performed before >> qtail = qtail->next > >X3J11/88-158, page 10, line 22: "The grouping of an expression does not >completely determine its evaluation." This is distasteful and will continue to be distasteful so long as assignment is considered an operator. Could someone please email me a copy of the rationale for this rule? >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." Huh? >X3J11/88-158, page 53, line 33: "The order of evaluation of the operands >[of an assignment operator] is unspecified." This one speaks of the left and right sides of a single assignment-operator, and seems to controvert the (formerly) specified right-to-left grouping of strings of assignments. >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? Especially elucidations on the possibility of that "intentionally." Doug? >The following should always work (assuming NULL is defined by the >appropriate #include): > (qhead ? qtail->next = qnew : qhead = qnew), (qtail = qnew)->next = NULL; I think it's time just to do: if (qhead) qtail->next = qnew; else qhead = qnew; qtail = qnew; qtail->next = NULL; Except for the loss of the extra capabilities of an expression. --Blair "No pain, uh, no pain."