I would say that the fact that i++ is a post-increment ensures only that the value returned from this expression is before the increment. However, nothing seems to say that the increment itself (the blocking assignment) has to happen before the whole RHS expression is evaluated. On the contrary, LRM explicitly says that the ordering of the assignment operations relative to any other operations within an expression is undefined, implying that the assignments may happen even before other operations in the same expression are performed (just like it happens with the assignment operator in your first example). So, if i++ is evaluated first, then the value is incremented, and then the i = i - 1 is performed, we get 10 + (i = 11 - 1) == 10 + 10 == 20. Still, I agree that the simple reference to the 18, 19, 20 numbers is confusing and should probably be either removed or elaborated. --Yulik. -----Original Message----- From: owner-sv-bc@server.eda.org [mailto:owner-sv-bc@server.eda.org] On Behalf Of Stuart Sutherland Sent: Friday, September 01, 2006 2:22 PM To: sv-bc@server.eda.org Subject: [sv-bc] Question on 1800 section 8.3 Section 8.3 of the 1800 standard contains the following example and explanation: i = 10; j = i++ + (i = i - 1); After execution, the value of j can be 18, 19, or 20 depending upon the relative ordering of the increment and the assignment statements. Can anybody detail the three orders of execution that would lead to these three possible results? The only combinations I can come up with are: j = 9 + 9 (i-1 is evaluated first, and used as the value of i++) j = 10 + 9 (i used as the value for i++ first, and then i-1 is evaluated) It seems to me that since i++ is a post-increment, it cannot change i until after j has been assigned. Thanks, Stu ~~~~~~~~~~~~~~~~~~~~~~~~~ Stuart Sutherland stuart@sutherland-hdl.com +1-503-692-0898Received on Fri Sep 1 05:26:48 2006
This archive was generated by hypermail 2.1.8 : Fri Sep 01 2006 - 05:26:57 PDT