Which is better?
M. J. Shannon, Jr.
mjs at alice.UUCP
Wed Dec 12 00:44:43 AEST 1984
The question asked was, `Which generates better code?':
if (exp)
{
stuff;
goto, continue, break, or return;
}
any of the other 3;
or:
if (exp)
{
stuff;
goto, etc.
}
else
{
any of the other 3;
}
The answer should be that it makes no difference, and for the compilers
I have access to, it doesn't if you use the -O flag. If you don't use
an optimizer, then the 2nd case above might generate a branch to a
branch to implement `one of the other 3'. However, if the compiler is
sufficiently `smart', then it will recognize that the `else' is
superfluous, and nicely fail to generate the branch to branch.
Thus, the answer is that the first form above will generate no worse
code than the 2nd, but any `reasonable' compiler will generate the same
code for both.
--
Marty Shannon
UUCP: {alice,research}!mjs
(rabbit is dead; long live alice!)
Phone: 201-582-3199
More information about the Comp.lang.c
mailing list