Subject: ANSI C sequence points and the single-update restriction (Was: More issues)
From: Brad Pierce (Brad.Pierce@synopsys.com)
Date: Thu Jan 02 2003 - 12:08:17 PST
According to --
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/ht
ml/_clang_c_sequence_points.asp
Between consecutive "sequence points" an object's value can be modified only
once by an expression. The C language defines the following sequence points:
Left operand of the logical-AND operator (&&).
Left operand of the logical-OR operator (||).
Left operand of the comma operator.
Function-call operator.
First operand of the conditional operator.
The end of a full initialization expression.
The expression in an expression statement.
The controlling expression in a selection (if or switch) statement.
The controlling expression of a while or do statement.
Each of the three expressions of a for statement.
The expression in a return statement.
According to --
http://infoweb.magi.com/~anderson/cpitfall/pit13.html --
Section 3.3 of the ANSI C standard 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.
In other words, the expression:
x = x + 1;
"is allowed, while:
x = ++x + 1;
"is not."
See also http://ccs.ucsd.edu/c/express.html#Order%20of%20Evaluation .
This archive was generated by hypermail 2b28 : Thu Jan 02 2003 - 12:08:53 PST