Evaluation order of assignment.
Liber
nevin1 at ihlpb.ATT.COM
Thu Aug 18 10:00:45 AEST 1988
In article <957 at orion.cf.uci.edu> schmidt at bonnie.ics.uci.edu (Douglas C. Schmidt) writes:
>Is the following always guaranteed to produce the "intended" result:
>[...]
> return(head->next = head = (struct list *) malloc(sizeof(struct list)));
>Since assignment associates from right-to-left this
>will alway work, right (cryptic style notwithstanding !! ;-)).
No (you should probably get a compiler warning). Although assignment
*associates* from right-to-left, assignment does not (necessarily)
*evaluate* from right-to-left. All that associativity means is that
(a) = (b) = (c);
(where a, b, c are expressions and a,b both produce lvalues) is
equivalent to
( (a) = ( (b) = (c) ) );
and not
( ( (a) = (b) ) = (c) );
order of evaluation of the expressions a, b, c is still undefined.
--
_ __ NEVIN J. LIBER ..!att!ihlpb!nevin1 (312) 979-???? IH 4F-410
' ) ) There is something embarrassing about working at
/ / _ , __o ____ AT&T and not being able to get a *PHONE*! :-)
/ (_</_\/ <__/ / <_ These are solely MY opinions, not AT&T's, blah blah blah
More information about the Comp.lang.c
mailing list