Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!crackers!jjmhome!smds!rh From: rh@smds.UUCP (Richard Harter) Newsgroups: comp.lang.c Subject: Re: Usage of goto's Summary: don't use goto's for efficiency in portable code Message-ID: <201@smds.UUCP> Date: 30 Sep 90 01:33:46 GMT References: <1990Sep28.121230.17767@NCoast.ORG> <5624@stpstn.UUCP> Organization: SMDS Inc., Concord, MA Lines: 28 In article <5624@stpstn.UUCP>, lerman@stpstn.UUCP (Ken Lerman) writes: > In article <1990Sep28.121230.17767@NCoast.ORG> ramsey@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.