Re: What is a sequence point?

From: pete (pfiland_at_mindspring.com)
Date: 02/11/05


Date: Fri, 11 Feb 2005 05:56:20 GMT

Deniz Bahar wrote:
>
> I know the basic definition of a sequence point (point where all side
> effects guaranteed to be finished), but I am confused about this
> statement:
>
> "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."
>
> Can someone give me examples of expressions that "barely" break this
> rule (the type a newcomer might trip over)?
>
> If you are between sequence points,
> then what does that second sentence
> mean "prior value"?

(p = p -> next = q)

The above doesn't specify the order of assignment and is undefined.
It could be either (p = q, p -> next = q) or (p -> next = q, p = q).

(i = x[i]++)
The above is being debated on comp.std.c
The i in x[i]++ is evaluated only once, but for two reasons.
It's evaluated to determine the value of the right operand of
the assignment operator, but also to determine the address of
the lvalue of the increment operator.

-- 
pete


Relevant Pages

  • Re: Must an expression be evaluated before its value is used?
    ... this is not a sequence point. ... The evaluation dependency has a consequence of ... seperate the assignment of 5 to x from the assignment of 11 to x. ... comma operator without first evaluating it's second operand. ...
    (comp.std.c)
  • Scott & Andrei article on DCLP and threading... Flawed ?
    ... am unable to make a solid case for strict ordering of 1,2 and 3. ... "As we tried to point out in the article, sequence points don't offer ... state of the execution environment. ... There is a sequence point at the completion of evaluation of each ...
    (comp.lang.cpp)
  • Re: Linux X demo
    ... precedence to the order of evaluation. ... evaluation of expressions is undefined. ... THE ORDER OF EVALUATION BETWEEN SEQUENCE POINTS. ...
    (alt.lang.asm)
  • Re: Must an expression be evaluated before its value is used?
    ... properly define the ordering of sequence points. ... The evaluation order is defined by the abstract machine (even if it is ... there is a sequence point after the evaluation of the first operand. ... "2 The left operand of a comma operator is evaluated as a void ...
    (comp.std.c)
  • Re: sequence points in subexpressions
    ... the evaluation of an expression also includes side effects, ... before the assignment operation on the left operand. ... operand follows a sequence point. ... of the right and left operands of the assignment operator. ...
    (comp.lang.c)