How to understand C FAQ 3.8?

From: mrby (bianying_at_msn.com)
Date: 11/30/04


Date: Tue, 30 Nov 2004 21:52:45 +0800

Hi,

I was reading section 3 of the C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html

I need more information about question 3.8:

==================
3.8: How can I understand these complex expressions? What's a
"sequence point"?

A: A sequence point is a point in time (at the end of the
evaluation of a full expression, or at the ||, &&, ?:, or comma
operators, or just before a function call) at which the dust
has settled and all side effects are guaranteed to be complete.
The ANSI/ISO C Standard states that

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.

The second sentence can be difficult to understand. It says
that if an object is written to within a full expression, any
and all accesses to it within the same expression must be for
the purposes of computing the value to be written. This rule
effectively constrains legal expressions to those in which the
accesses demonstrably precede the modification.

See also question 3.9 below.

References: ISO Sec. 5.1.2.3, Sec. 6.3, Sec. 6.6, Annex C;
Rationale Sec. 2.1.2.3; H&S Sec. 7.12.1 pp. 228-9.
=========================

I understand "a legal expression (i.e: not undefined)" as:
1) Any variable should be modified at most once.
2) The variable modified should not be referenced
   "elsewhere" within the expression.

So ... I can tell the following code are undefined:

a[i] = i++;
    //i is modified and referenced "elsewhere"
    //see FAQ 3.1.

i++*i++
    // i is modified twice!

But how about *p++ ? It is commonly used and should not
be "undefined" behavior, but p is modified and the new
value is accessed.

This is conflict with my understanding and with FAQ 3.2.
It said that post ++ merely guarantees that the variable
will be incremented before the expression "finishes", how
can it gurantee that p is incremented right before the *
access? (i.e: Is there the possibility that * operator accesses
the old value of p)

I am not sure I have made myself clear.
Will some guy explain it for me?

Thanks,
mrby



Relevant Pages

  • Re: What is a sequence point?
    ... >> If you are between sequence points, ... I read the FAQ before my original post. ... This rule effectively constrains legal expressions ... standard than the standard itself. ...
    (comp.lang.c)
  • Re: VMS startup problem?
    ... > You won't need the reboot either, as the sequence shown in the FAQ ... But if you had set STARTUP_P1 to "MIN", you'll only get a minimum boot ...
    (comp.os.vms)
  • Re: Order of function parameters evaluation
    ... >> Reading the faq will be helpful. ... > function* does NOT introduce a sequence point, ... If you read the language grammar, you will see that a comma ... used to separate function arguments is not actually an operator. ...
    (comp.lang.c)
  • Re: Can we arrange the sequence of tasks instead of inputting the start-end time.
    ... You might like to see FAQ Item: ... > Can we arrange the sequence of tasks instead of inputting the ...
    (microsoft.public.project)
  • Re: How to understand C FAQ 3.8?
    ... >> Between the previous and next sequence point an ... >> The second sentence can be difficult to understand. ... >> accesses demonstrably precede the modification. ... modifying objects would be pretty damn ...
    (comp.lang.c)