http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59538
--- Comment #6 from Arsham Skrenes <arsham at skrenes dot com> --- (In reply to Dominique d'Humieres from comment #5) > > Also, is there a directive that I can use to explicitly tell GCC > > to not remove a loop (without having to resort to a compiler flag > > which is global, PRINTING A VARIABLE, or using the 'volatile' keyword > > which de-optimizes the caching of the target variable)? Thanks! > > Try to print i instead of NTH! The basic way to avoid the removal of loops > in a benchmark is to consume in some way some of the computed data (in some > cases the optimizer may even be clever than you think). Your solution is "printing a variable" which if you look at my question, is exactly what I want to avoid. Before even writing that comment, I had already added, after line 35, the following: printf("%d\r",i); It gets overwritten by the next print statement and retains the loop. It's a hack and not at all elegant. That is why I'm asking if there is a compiler directive I can use instead. If one doesn't exist, there really ought to be a directive to retain a loop and at the very least, such "optimizations" should output a warning (you shouldn't be obliterating blocks of code without so much as a warning). The developer should know if a block of code has been deemed unreachable or useless and therefore not included.