Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site harvard.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!breuel From: breuel@harvard.ARPA (Thomas M. Breuel) Newsgroups: net.lang.c Subject: Re: goto's in 'C' Message-ID: <324@harvard.ARPA> Date: Thu, 24-Jan-85 10:21:49 EST Article-I.D.: harvard.324 Posted: Thu Jan 24 10:21:49 1985 Date-Received: Fri, 25-Jan-85 21:56:01 EST Distribution: net Organization: Harvard University Lines: 29 |From rpw3@redwood.UUCP (Rob Warnock) Tue Jan 22 21:17:38 1985 | |+--------------- || >[rpw3] The incidence of the "goto" in C code is so rare anyway, I dare say || >we could abolish it altogether (replacing it with BLISS's "leave") || >and not miss the loss. (I certainly never missed it in BLISS.) || I would miss it. I have never used it for breaking out of loops or || making loops in the conventional sense. It is extremely useful, though, || for 'hardcoding' finite state machines. If they contain more than say 3 || or 4 states, the use of structured constructs is awkward... || Thomas. |+--------------- | |Well, that depends on what "structured construct" you use. The standard |technique (criticized by Wulf in "Global Variable Considered Harmful") is |to use a (global) state variable which is really the "PC" of your state |machine, with assignments to "state" instead of "goto"s: I would not refer to a state machine with an explicit state variable as 'hard coded' (sorry about the fuzzy terminology). It remains that in many cases, state machines implemented with 'goto' are at least as readable as those implemented using a state variable and a while loop. In addition, they don't require you to define your states in a separate place and they are more efficient. 'goto' is useful when used with care, and not providing it in a systems programming language like 'C' would probably be a mistake. Thomas.