RE: Logic Unknown - help needed 04-19-2013, 06:00 AM
#21
(04-18-2013, 11:10 PM)ArkPhaze Wrote: Therefore @Deque you are also wrong. :lol:
Deque Wrote:Every compiler might return a different result here, because some evaluate ++y before y++ and some do it the other way around.
It does depend on the compiler, but the fact is regardless of the compiler, for the code OP posted, you should never get a result that deviates from 8, otherwise you have a shit compiler. If regardless of the undefined behavior, you meant left to right vs. right to left. Therefore the sequence point is really irrelevant as it is meaningless here.
So... "undefined" theoretically, and "defined" in reality I suppose, since the result of 8 is guaranteed? :whistle:
Reason?
[y = 3] for ... x=(y++)+(++y):
- x = 3 -> y is incremented to 4 AFTERWARDS.
x = 3, + (y which is 4, incremented immediately which is 5)
therefore: x = 3 + 5 = 8
so... x = 8
[y = 3] for ... x=(++y)+(y++):
- x = (y = 3, incremented to 4 immediately)
therefore: x = 4
x = 4, + (y = 4, incremented to 5 AFTERWARDS)
therefore: x is now 4 + 4 = 8
so... x = 8
OP's math is just wrong. But in both cases y still results in 5 after the assignment.
Deque Wrote:Let's hope Creed is using Orwells Dev-C++ and not the unmaintained original from Bloodshed.
That bloodshed one is the only one I usually think of when I hear DevC++ anywhere... It's a shame because of the existence of Orwells compiler.
I'm going to tag @Creed in this post as well as I think he should read my math above.It's essential for understanding auto-incrementing operators.
So you just take as a given that the side effect of y++ takes place before the ++y is evaluated? You can't.
For the compiler it would be right to do this:
y=3
y++ --> value of y is still 3, increment happens later
++y --> value of y is 4
x = 4 + 3 --> = 7
increment y --> value of y is 5
So, again, the behaviour is undefined, no matter how you put it.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.
Expressed feelings are just an attempt to simulate humans.
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)


It's essential for understanding auto-incrementing operators.![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
![[Image: 9kGmkzE.png]](http://i.imgur.com/9kGmkzE.png)