Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mbabauer

macrumors regular
Feb 14, 2006
105
0
Honestly, this looks like a difference in how the respective compilers try to optimize code. I don't think this has to do so much with the order that the pieces are interpreted as much as the compiler trying to save some bytes of memory.

Think about it this way. WHY would the compiler think both 'n' vars were the same? The only answer is that it seems the compiler saw the first ++n, then the second and said "instead of putting this in its own register, lets save a little and use the same one".

Perhaps some optimization to minimize memory footprint is turned on in one compiler but not the other?
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
MarkCollette said:
Thanks guys.

I posted that because I wanted to show how certain programming problems are caused by limitations of how computers work, under the covers, such as this issue of synchronising variables in RAM and registers. This is also the root cause of why accessing variables in multiples threads is unsafe, and so is actually an important issue.

Mark, your post reminded me of my programming language concepts class. I wanted to take compiler design last quarter, but it didn't fit my schedule. They don't offer the graduate version again before I'll be finished, so oh well. Maybe I'll come back and take it just for fun.

Great post. :)
 

bbarnhart

macrumors 6502a
Jan 16, 2002
824
1
Catfish_Man said:
http://thedailywtf.com/

Unfortunately, code much worse than the OP shows up in real life :(

Thanks for this link. I didn't know about this site and it cracked me up. Reading the site and seeing the submissions for bad code it makes me think of my job and this person I worked with.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.