powerful expressions
Blair P. Houghton
bph at buengc.BU.EDU
Sun Dec 10 03:34:56 AEST 1989
In article <462 at cpsolv.UUCP> rhg at cpsolv.uucp (Richard H. Gumpertz) writes:
>In article <5040 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) 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;
>...
>>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."
More information about the Comp.lang.c
mailing list