🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4452

Re: On sequence points and evaluation order

#4452
From: Mark Brader
Date: Sat, 09 Dec 1995 05:11
57 lines
2981 bytes
> > > The example that really baffles me is '(++i,j)+(j,++i)',

Call it Expression A.

> > > because the standard assumes an ordering of operations without
> > > defining what that ordering is. ...

> > Right; the ordering is unspecified -- except that the left-hand ++i must
> > be evaluated before the left-hand j with a sequence point intervening,
> > and the right-hand j must be evaluated before the right-hand ++i with
> > a sequence point intervening.  Therefore the sequence
> > 	1. right-hand j
> > 	2. left-hand ++i
> > 	3. right-hand ++i
> > 	4. left-hand j
> > is possible. ... Therefore the expression [causes] undefined behavior.
> 
> Please, Oh Great Guru, now explain what is meant by the sentence in the
> standard which says "At sequence points, volatile objects are stable in
> the sense that previous evaluations are complete and subsequent
> evaluations have not yet occurred.",

The Great Guru says that this sentence is self-explanatory.  And so do I. :-)

> if we assume that 'i' and 'j' are volatile.

If you're talking specifically about Expression A, the sentence does not
apply to it, because the expression causes undefined behavior.
 
> E.g., does the concept of a 'previous sequence point' imply a partial
> or complete ordering?

Time is linearly ordered, therefore a complete ordering of sequence
points exists.  (It may be possible for two sequence points to occur
simultaneously in code such as Expression A, but no program could detect
this, so it doesn't matter.)

> And is such an ordering decidable from the C code alone,

Not in the presence of code such as Expression A.  The relative ordering
of the sequence points from the comma operators depends on aspects of the
evaluation order which are explicitly unspecified.

> or is it implementation-specific?  And is it decidable during
> translation, or can it be data-dependent?

When it is unspecified, it could be completely random.  To drop into the
practical for a moment, it could depend on which of several CPUs on a
machine happened to be available.  Of course, often the order of sequence
points is fully specified by the standard; this is the case with code like
a++;b++;c++;d++; or (i>.9)?--i:--j||--k;;; it just isn't *always* true.
-- 
Mark Brader                     "[This computation] assumed that everything
msb@sq.com                       would work, a happy state of affairs found
SoftQuad Inc., Toronto           only in fiction."      -- Tom Clancy

My text in this article is in the public domain.
Technical Details
Message-ID: <1995Dec9.051121.7603@sq.com>
Path: arc1-ca.pugleaf.net!nntp.coast.net!torn!sq!msb
References: <49l428$od0@bolverk.cs.cornell.edu> <49vgb5$muj@lyra.csx.cam.ac.uk> <1995Dec6.002655.7556@sq.com> <4a3va2$khu@lyra.csx.cam.ac.uk>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!nntp.coast.net!torn!sq!msb
From: msb@sq.com (Mark Brader)
Subject: Re: On sequence points and evaluation order
Message-ID: <1995Dec9.051121.7603@sq.com>
Organization: SoftQuad Inc., Toronto, Canada
References: <49l428$od0@bolverk.cs.cornell.edu> <49vgb5$muj@lyra.csx.cam.ac.uk> <1995Dec6.002655.7556@sq.com> <4a3va2$khu@lyra.csx.cam.ac.uk>
Date: Sat, 9 Dec 1995 05:11:21 GMT