for(;;) vs. while(1) is a draw

Guy Harris guy at auspex.auspex.com
Sun May 27 04:31:32 AEST 1990


>Ayup.  They'd be optimizing without being asked to,

So what?

>	for(;;) statement
>
>	while(1) statement
>
>	label: statement if(1) goto label;
>
>are all the same; exactly the same, when translated into object code
>without thinking about it.  You could contend that the third is
>my invention, but the standard says the first two are identical.

The standard does *NOT* say, in any way, shape, or form, that they are
"exactly the same, when translated into object code without thinking
about it".  (The standard doesn't even say that an implementation
necessarily translates them into object code!)  It just says that they
have to *act* the same.  How the compiler arranges that that happen is
*not* X3.159-1989's business.

>I didn't say the standard specified optimization.

Well, if you didn't say anything about what the standard said, why are
you saying it *here*?  As several people have noted, the standard does
not dictate, *one way or the other*, whether "for(;;)" and "while(1)"
have to generate the exact same object code; all it says is that the
object code generated, assuming object code is generated at all, has to
provide the same semantics for both constructs.

>I said the implementor did, or rather, the implementor specified a _lack_
>of it.  Then it went and optimized.

"Optimization" is in the eye of the beholder.  Perhaps that's why the
standard doesn't tend to talk about it?

*I* don't demand that a compiler, when no "optimization" is specified,
generate code by the most naive algorithm possible, i.e. "without
thinking about it".  If you do, that's your choice.  For better or
worse, plenty of other people, I suspect, don't demand it either.



More information about the Comp.std.c mailing list