Armenian Knowledge Base  

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

Reply
 
LinkBack Thread Tools
Old 02.10.2001, 03: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, 07:53   #2
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Downloads: 0
Uploads: 0
Reputation: 18 | 5
Post

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, 01:23   #3
Moderator
 
acid's Avatar
 
Join Date: 09 2001
Location: South Korea, Gumi
Posts: 7,699
Downloads: 102
Uploads: 34
Blog Entries: 16
Reputation: 561 | 6
Arrow

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
Reply

Thread Tools


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

All times are GMT. The time now is 11:19.


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