News for hackers. Stuff that matters.
Re:Optimizing C++ Code: Dead Code Elimination by scott_s on Wednesday August 14, 2013 @02:31PM (#6213307)
An empty loop that has no computation but loops forever has an observable side-effect.
Re:Optimizing C++ Code: Dead Code Elimination by nhaehnle on Wednesday August 14, 2013 @02:51PM (#6213453)
Go read page 14 of this: http://isocpp.org/files/papers/N3690.pdf ;-)

Essentially, C++ does not consider looping forever to be a side effect. You have to do something like writing to a volatile variable to ensure that the compiler does what you want.

Re:Optimizing C++ Code: Dead Code Elimination by gizmo686 on Wednesday August 14, 2013 @03:44PM (#6213750)
The relevent part of page 14:

"The implementation may assume that any thread will eventually do one of the following: — terminate, — make a call to a library I/O function, — access or modify a volatile object, or — perform a synchronization operation or an atomic operation. [ Note: This is intended to allow compiler transformations such as removal of empty loops, even when termination cannot be proven. — end note ]"