Usage of goto's

Richard Harter rh at smds.UUCP
Sun Sep 30 11:33:46 AEST 1990


In article <5624 at stpstn.UUCP>, lerman at stpstn.UUCP (Ken Lerman) writes:
> In article <1990Sep28.121230.17767 at NCoast.ORG> ramsey at NCoast.ORG (Cedric Ramsey) writes:
> ->Is it okay for a programmer to break a TABOO intentionally; by design?
> 
> IMHO, yes.  In one situation where I cared about efficiency, I felt
> justified in using a bunch of gotos in the same program.  The code looked
> something like this.

[example of state machine code deleted.]

Actually, there is a good chance that you lost efficiency rather than gained
it.  Many optimizing compilers don't deal well with goto's.  As I understand
it, they make the register assignment task messy and their presence
invalidates many assumptions used in optimizing code in blocks.  Switches
for contiguous integer ranges typically optimize out to a range check and
a branch from a jump table.  The 3-4 instructions that you pay for a range
check and two jumps will be outweighed by extra instructions induced by
less efficient optimization.  In any case the potential gain is negligible
unless the state execution code is mostly one liners.

I have nothing against goto's -- I average about 1 per 20,000 lines of code.
However IMHO you should scrupulously avoid them in code which is intended
to be both portable and efficient.
-- 
Richard Harter, Software Maintenance and Development Systems, Inc.
Net address: jjmhome!smds!rh Phone: 508-369-7398 
US Mail: SMDS Inc., PO Box 555, Concord MA 01742
This sentence no verb.  This sentence short.  This signature done.



More information about the Comp.lang.c mailing list