No sequence points in assignment

Joe English jeenglis at nunki.usc.edu
Wed Sep 13 10:43:36 AEST 1989


karzes at mfci.UUCP (Tom Karzes) writes:
>I have a question about assignment expressions.  According to the standard,
>an assignment expression does not introduce a sequence point, although the
>side effect of updating the stored value of the left operand must occur
>between the previous sequence point and the next sequence point.  This
>seems to imply that in an expression with multiple assignments, the actual
>assignments may occur in any order provided the stored values can be
>determined and the assignments all take place between the previous
>sequence point and the next sequence point.  If this interpretation is
>correct, it seems to me that it can lead to some counter intuitive
>results.  For example, consider the following statement:
>
>    x = a + (x = b);
>
>Could the assignment for (x = b) be performed after the outer
>assignment?  Since it knows that the value of (x = b) is b,
>can't it delay the assignment of b to x?  I.e., could this
>statement be validly translated as "evaluate b, evaluate a,
>add, assign the result to x, assign the previous result, b,
>to x"?


As far as I know, yes.  I have a question, though:  Does it really
matter?  There seems to be a lot of traffic lately asking questions
like:  "Will (obviously buggy and weird code) work like you would
expect it to, or is the compiler allowed to do something other than
What I Mean?" 

I fail to see how these questions are relevant, unless you're trying to
write incredibly hairy expressions like using a temporary variable
multiple times in a single expression.  (Which you probably shouldn't
be doing in the first place!)

Just wondering,

--Joe English

  jeenglis at nunki.usc.edu



More information about the Comp.std.c mailing list