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

Tom Tkacik tkacik at rphroy.UUCP
Mon May 28 09:34:07 AEST 1990


In article <5905 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>It requires a stricter definition of "non-optimizing" than
>it seems most people carry around with them.  They certainly
>don't see it the way I do.

>Here we go:

>	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.
>I'd expect a compiler with no heuristics in it to prove me right.

>Add optimization, and make it good, and it all becomes

>	label: statement goto label;

>>>"The semantic descriptions in this standard describe the behavior
>>>of an abstract machine in which issues of optimization are irrelevant."
>>>(ANSI X3.159-1989, Sec. 2.1.2.3, pp. 8, ll. 29-30)
>
>I didn't say the standard specified optimization.  I said the
>implementor did, or rather, the implementor specified a _lack_
>of it.  Then it went and optimized.

Not turning for(;;) into while(1) is not an optimization.  I have not read the
standard, (am I still allowed to make a comment in forum:-), 
but from the massive amounts of discussion going on, it appears to
say that  for(;;) should act like while(1).

This is a semantic issue.  For(;;) should ACT exactly like while(1).
It does not seem be say that they should be the same, just act the same.
Therefore, a non-optimizing compiler could generate a loop and branch
for for(;;), because it is easier to do, knowing that this is semantically
the same as while(1), and not be doing any optimization that Blair claims
has just occured.

No internal form of while(1) was generated and optimized away.
It was never there to start with.  The standard does not say it has
to be, as long as the semantics are the same (which they are).
The compiler gave for(;;) the most basic definition, the semantics of while(1),
and generated stupid code, loop and branch.

Can we get on to something more enlightening than when is
legally a non-optimization?

When I feel the need to add something, things must surely have degenerated :-).
-- 
Tom Tkacik			GM Research Labs,   Warren MI  48090
Work phone: (313)986-1442	uunet!edsews!rphroy!megatron!tkacik
"I'm president of the United States, and I'm not going to eat anymore broccoli."
						--- George Bush



More information about the Comp.std.c mailing list