🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4438

Re: On sequence points and evaluation order

#4438
From: Nick Maclaren
Date: Wed, 06 Dec 1995 11:37
49 lines
2750 bytes
In article <1995Dec6.002655.7556@sq.com>, msb@sq.com (Mark Brader) writes:
|> Nick Maclaren (nmm1@cus.cam.ac.uk) writes:
|> > The example that really baffles me is '(++i,j)+(j,++i)', 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.  (The ++ can be broken up into subsidiary operations, but it
|> isn't necessary for this analysis.)  The comma operators force sequence
|> points between steps 1 and 3, and between 2 and 4, but neither of these
|> sequence points has to be between 2 and 3.  Therefore i may be modified
|> twice without a sequence point intervening - whether this happens or not
|> is unspecified, since it depends on the evaluation order.  Therefore it
|> is unspecified whether or not the expression causes undefined behavior.
|> Therefore the expression does cause undefined behavior.$
|> 
|> See?  It's not so hard.

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.", if we assume that 'i' and 'j' are
volatile.

E.g., does the concept of a 'previous sequence point' imply a partial
or complete ordering?  And is such an ordering decidable from the C code
alone, or is it implementation-specific?  And is it decidable during
translation, or can it be data-dependent?

Actually, I am pretty sure that I know how you interpret the standard,
but I am also sure that (a) it doesn't confirm your interpretation
unambiguously and (b) many or most implementors will assume variant
readings.


Nick Maclaren,
University of Cambridge Computer Laboratory,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email:  nmm1@cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679
Technical Details
Message-ID: <4a3va2$khu@lyra.csx.cam.ac.uk>
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1
References: <49l428$od0@bolverk.cs.cornell.edu> <49qtc0$72g@light.twinsun.com> <49vgb5$muj@lyra.csx.cam.ac.uk> <1995Dec6.002655.7556@sq.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1
From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Newsgroups: comp.std.c
Subject: Re: On sequence points and evaluation order
Date: 6 Dec 1995 11:37:38 GMT
Organization: University of Cambridge, England
Message-ID: <4a3va2$khu@lyra.csx.cam.ac.uk>
References: <49l428$od0@bolverk.cs.cornell.edu> <49qtc0$72g@light.twinsun.com> <49vgb5$muj@lyra.csx.cam.ac.uk> <1995Dec6.002655.7556@sq.com>
NNTP-Posting-Host: ursa.cus.cam.ac.uk