Article View: comp.std.c
Article #4424Re: On sequence points and evaluation order
From: Mark Brader
Date: Wed, 06 Dec 1995 00:26
Date: Wed, 06 Dec 1995 00:26
33 lines
1891 bytes
1891 bytes
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. $ - This follows from the rule about implicitly undefined behavior that is bundled in with the definition if "undefined behavior" in 3.16/1.6. -- Mark Brader, msb@sq.com "Logic is logic. That's all I say." SoftQuad Inc., Toronto -- Oliver Wendell Holmes My text in this article is in the public domain.
Technical Details
Message-ID:
<1995Dec6.002655.7556@sq.com>Path:
arc1-ca.pugleaf.net!nntp.coast.net!torn!sq!msbReferences:
<49l428$od0@bolverk.cs.cornell.edu> <49qtc0$72g@light.twinsun.com> <49vgb5$muj@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: <1995Dec6.002655.7556@sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <49l428$od0@bolverk.cs.cornell.edu> <49qtc0$72g@light.twinsun.com> <49vgb5$muj@lyra.csx.cam.ac.uk> Date: Wed, 6 Dec 1995 00:26:55 GMT