This is the mail archive of the
mailing list for the GCC project.
Re: confused at code generation for a empty loop
On Friday 30 November 2007 15:17, Tim Prince wrote:
> PRC wrote:
> > while( flag == 0 ) ;
> > I wonder why gcc generates code for a empty loop like that. Is it a bug
> > or for optimization in some case?
> This subject has been debated at length, and some programmers rely on
> the current gcc treatment. More programmers rely on loops whose exit
> condition should not be optimized away, but does get "optimized" away by
> unsafe "optimizations" by certain compilers, including gcc -ffast-math.
A programmer who writes code whose correctness relies on certain properties of
the optimizer isn't worth the money he wants you to pay him. A programmer
should rely on the specified semantics of the language he's using. C and C++
both assume, that the program flow is the only source of side effects, unless
told otherwise. "volatile" is the tool to advise the compiler that additional
mutators exist and that these mutators will produce side effects in a
specified memory locations. End of story.