No sequence points in assignment

Tom Karzes karzes at mfci.UUCP
Thu Sep 14 03:20:40 AEST 1989


In article <1989Sep13.005247.20121 at algor2.algorists.com> jeffrey at algor2.UUCP (Jeffrey Kegler) writes:
-In article <1021 at m3.mfci.UUCP> karzes at mfci.UUCP (Tom Karzes) writes:
->Consider the following statement:
->
->    x = a + (x = b);
->
->Could the assignment for (x = b) be performed after the outer
->assignment?
-
-In ANSI C (3.3), this is undefined behavior, meaning anything (core
-dump, generation of random number, etc.) can happen.  In all
-likelihood, and in Classic C, you get the assignments performed in
-whatever order amuses the compiler.

Yes, this is what I was looking for.  I simply didn't look in the right
place (I looked under the description of assignment operators).  The
second paragraph in section 3.3 says:

    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.

Presumably a good compiler would give a warning in the obvious case
where there are multiple assignments to a scalar with no intervening
sequence points.



More information about the Comp.std.c mailing list