Topic: Sequence points (was Order of evaluation)


Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: 1995/05/11
Raw View
In article <3ojle9$6nv@giga.bga.com>, Jamshid Afshar <jamshid@ses.com> wrote:
>
>Can you provide more information about the flaw or explain why, though
>the C committee has determined that sequence points work well enough
>for C, they're not good enough for C++.

 They are good enough for C++ in my opinion, for the same
reason they're good enough for C: but they don't "work" properly
in general.

>That's good to know, but what do you mean that only the "concept" of
>sequence points has been adopted?  Was the ISO C rule about modifying
>an object twice between two sequence resulting in undefined behavior
>NOT adopted by the C++ commitee?

 That was what I believed. But 5/4 disagrees with me, the
ISO C rule appears in the WP. (The index is incomplete, I did not
find this clause before :-((

 However, it is a bit confusing because the requirement
is also stated that the behaviour is undefine unless _all_ possible
orderings conform. That isn't in the C Standard and meets one
of my objections.

>You wrote that:
>
> cout << func (++i, ++i);
>
>results in undefined behavior in ISO C, but seemed to imply that this
>is not true in C++:

 I withdraw the claim.

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189





Author: jamshid@ses.com (Jamshid Afshar)
Date: 1995/05/07
Raw View
In article <D7o1Lv.M2D@ucc.su.OZ.AU>,
John Max Skaller <maxtal@Physics.usyd.edu.au> wrote:
>[...]
> Sorry, it is silly of me to attribute knowledge to
>a committee. Only humans have knowledge. Ron is not aware
>of the flaw. Plauger and Plum are. It arises in a few
>circumstances and, being known, is not considered serious
>enough to warrant a complete rebuilding of the C execution model.
>(The flaw is not in the rules in the C Standard, but in the very notion
>of sequence points. They simply don't work. They cannot be
>"fixed" no matter how many Defect reports are submitted.)

Can you provide more information about the flaw or explain why, though
the C committee has determined that sequence points work well enough
for C, they're not good enough for C++.

> As a matter of interest the _concept_ of sequence points was
>added to C++ due to a motion by Tom Plum, and the ISO C sequence
>points in particular were added due to a friendly amendment move by ME.
>
> I accepted Tom's argument that it was better to
>adopt the C sequence point model, which is flawed but
>works most of the time, than have no execution model
>in the Working Paper at all, or spend a whole lot of time
>developing a new model.

That's good to know, but what do you mean that only the "concept" of
sequence points has been adopted?  Was the ISO C rule about modifying
an object twice between two sequence resulting in undefined behavior
NOT adopted by the C++ commitee?  You wrote that:

 cout << func (++i, ++i);

results in undefined behavior in ISO C, but seemed to imply that this
is not true in C++:

JMS>however the result has to be 2+3. Either the left or right [...]

JA>Stop right there, John.  Modifying an object twice between two
JA>sequence points results in undefined behavior, period.

JMS> I confirm you are correct for ISO C. I also note there
JMS>is a serious BUG in the whole notion of sequence points which
JMS>leaves open to interpretation a few scenarios. [...]

What scenarios?  Has the C++ committee decided that code which results
in undefined behavior under ISO C must now results in only unspecified
behavior?

> I am not particularly happy with this state of
>affairs, as the model Jerry outlined was clearly superior.
>However, he did not provide a complete normative text
>of an execution model, and the ISO C Standard does,
>even if it is flawed.
>
> A "dirty" summary of the problem is that
>the notion doesn't nest -- it isn't recursive.

Can you elaborate?  I'm not sure what you mean by "they don't nest",
but even if they don't, why is that a problem?  From earlier in this
thread:

JA>[see comp.std.c reply to "write( write( stdout, ++i ), ++i );"]
JA>There is a sequence point at the point a
JA>function is called, but not between the evaluation of function
JA>arguments.

JMS> Yep, thats the bug. Sequence points don't nest.
JMS>Jerry Schwarz invented "actions" which did nest. Actions are
JMS>a much better idea I think.

Where's the bug?  The code results in undefined behavior -- I don't
understand what's wrong with that.

Jamshid Afshar
jamshid@ses.com