![]() |
![]() | #1 |
Младенец Join Date: 10 2001 Location: Houston, TX
Posts: 1
Downloads: 0 Uploads: 0
Reputation: 0 | 0 | ![]()
I have some problems for you, I'm a Lab Aide 3rd period at Clear Lake High in Hosuton, Texas, and the Comp Sci 1 students are doing the Increment/Decrement operators, and there are some small innacuracys between logic, and what our compilers are doing. On these computers we have Borland C++ 4, and MetroWorks CodeWarrior Pro 5.<BR>#include <iostream.h> int main()<BR>{ int x = 10; ++x = ++x + (x++ + ++x);<BR> cout << x << endl;<BR> <BR> return 0;<BR>} do this on paper, and then type it in, totally diffrent answers. any explainations? --Thx Dan |
![]() |
![]() | #3 |
Moderator Join Date: 09 2001 Location: South Korea, Gumi
Posts: 7,699
Blog Entries: 16 Downloads: 102 Uploads: 34
Reputation: 561 | 6 | ![]()
Well, it was confusing but if you look inside ISO/IEC 9899 you can find chapter like "Expressions - topic 4". Here it is: <BR>...<BR>4. Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual<BR>expressions, and the order in which side effects take place, is unspecified. Between the previous and<BR>next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an<BR>expression. Furthermore, the prior value shall be accessed only to determine the value to be stored. The<BR>requirements of this paragraph shall be met for each allowable ordering of the subexpressions of a full<BR>expression; otherwise the behavior is undefined. [Example:<BR>i = v[i++]; // the behavior is undefined<BR>i = 7, i++, i++; // ‘i’ becomes 9<BR>i = ++i + 1; // the behavior is undefined<BR>i = i + 1; // the value of ’i’ is incremented<BR>—end example]<BR>... <BR>I think it is clear enough that your expression is much more complicated version of i = ++i + 1, so the behavior will be what your compiler can produce <IMG SRC="smile.gif" border="0"> Hope it helps.<BR>acid [ October 02, 2001: Message edited by: acid ] |
![]() |
Sponsored Links |