AKB Forums

Go Back   AKB Forums > Technical sections > Languages, Compilers and Interpreters
Home Register Blogs FAQ Members List Calendar Downloads Arcade Mark Forums Read

Languages, Compilers and Interpreters C,C++,C#,.NET,Java,PHP,Perl,SQL and more

Troubles when posting message? Click here! :: Проблемы с отправлением сообщения? Нажмите сюда!

Reply
 
LinkBack Thread Tools Display Modes
Old Oct 2, 2001, 02:46   #1
Младенец
 
Join Date: Oct 2001
Location: Houston, TX
Posts: 1
Rep Power: 0
Reputation: 10
Send a message via ICQ to Dan Stone
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
Dan Stone is offline   Reply With Quote Quote selected
Old Oct 2, 2001, 06:53   #2
Administrator
 
greka's Avatar
 
Join Date: Sep 2001
Location: @work
Posts: 5,347
Rep Power: 10
Reputation: 23
Send a message via ICQ to greka
Post

how you're performing calculations ?<BR>I mean what answer is expected by you :-?<BR> <IMG SRC="smile.gif" border="0">
__________________
И повешенные могут качаться в неположенную сторону. /С.Е.Лец/
greka is offline   Reply With Quote Quote selected
Old Oct 3, 2001, 00:23   #3
Administrator
 
acid's Avatar
 
Join Date: Sep 2001
Location: Yerevan, Armenia
Posts: 7,155
Blog Entries: 15
Rep Power: 10
Reputation: 293
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 ]
__________________
Chat with acid


acid is offline   Reply With Quote Quote selected
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 00:09.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
This board was founded on September 29, 2001
Powered by Viper Internet

Affordable Web Hosting | ParevNet

Buy text link