Linked by Thom Holwerda on Wed 17th Nov 2010 23:10 UTC, submitted by Debjit
Permalink for comment 450753
To read all comments associated with this story, please click here.
To read all comments associated with this story, please click here.
News
Linked by Thom Holwerda on 06/19/13 23:02 UTC, submitted by M.Onty
Linked by Thom Holwerda on 06/19/13 22:28 UTC
Linked by Thom Holwerda on 06/18/13 22:33 UTC
Linked by Anonymous on 06/18/13 22:26 UTC
Linked by Thom Holwerda on 06/18/13 22:25 UTC
Linked by Thom Holwerda on 06/18/13 17:45 UTC
Linked by Thom Holwerda on 06/18/13 17:32 UTC, submitted by poundsmack
Linked by Thom Holwerda on 06/17/13 17:58 UTC
Linked by Thom Holwerda on 06/17/13 17:52 UTC
Linked by Thom Holwerda on 06/14/13 21:03 UTC
More News »
Sponsored Links



Member since:
2010-03-05
for (count=0;count<x;count++); y+=count
... is dead code when x=0 (resulting in y=y), as long as x isn't constant (read: calculated or given as input).
Well, it can notice that,
- given x <= 1, the loop is dead code (noop)
- given x > 1, the whole loop is equivalent to: y += x*(x-1)/2.
Hence, a really good compiler should probably replace the loop by a proper
if (x>1) y += x*(x-1)/2
Edit: what I'm trying to prove here is that, when different compiler optimizations start to work together, the results can be amazing and really difficult to predict. Put it in other way, you don't need *bad* code nor a silly programmer to produce code that can be significantly optimized...
Edited 2010-11-22 00:14 UTC