Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters

LinkBack Thread Tools
Old 02.10.2001, 02:46   #1
Join Date: 10 2001
Location: Houston, TX
Posts: 1
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Question ++/-- operators

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
Reply With Quote
Old 02.10.2001, 06:53   #2
greka's Avatar
Join Date: 09 2001
Location: inside myself
Posts: 5,368
Downloads: 0
Uploads: 0
Reputation: 18 | 5

how you're performing calculations ?<BR>I mean what answer is expected by you :-?<BR> <IMG SRC="smile.gif" border="0">
Reply With Quote
Old 03.10.2001, 00:23   #3
acid's Avatar
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 ]
Reply With Quote
Sponsored Links

Thread Tools

На правах рекламы:

All times are GMT. The time now is 04:02.

Powered by vBulletin® Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.