Xref: utzoo comp.lang.c:10024 comp.software-eng:536 comp.lang.misc:1566 Path: utzoo!mnetor!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c,comp.software-eng,comp.lang.misc Subject: Re: State Machines, The Ultimate Goto Message-ID: <27744@cca.CCA.COM> Date: 8 May 88 18:04:01 GMT References: <1988Apr8.183815.3187@utzoo.uucp> <449@goofy.megatest.UUCP> <2200@louie.udel.EDU> <587@vsi.UUCP> <27310@cca.CCA.COM> <760@dlhpedg.co.uk> <27568@cca.CCA.COM> <4627@ihlpf.ATT.COM> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Followup-To: comp.lang.misc Organization: Computer Corp. of America, Cambridge, MA Lines: 58 In article <4627@ihlpf.ATT.COM> nevin1@ihlpf.UUCP (00704a-Liber,N.J.) writes: >In article <27568@cca.CCA.COM> g-rh@CCA.CCA.COM.UUCP (Richard Harter) writes: >>Goto logic says leave and don't come back. >Not true. For example: > FOO: goto FOO; You misapprehend. This is not an example of 'goto' logic -- it is an implementation of a simple loop using goto's. >Goto logic says you can come here anytime you need to and from anywhere you >want to (within limits, of course). Well, this is a matter of terminology -- what precisely does one mean by the phrase 'goto logic', which is actually a neologism. Since I coined the phrase, I will claim priority and say it is my definitions that should be used :-). Seriously, however, your definition is not of much use, because what you say is true of procedure calls also. The difference is: Procedure logic: Record where you are now, transfer to a labelled block (called a procedure) and transfer back to the recorded transfer point upon completion of the block. Goto logic: Do not record where you are now; simply transfer to a labelled block (no standard name). Determine within the block the next block to be executed. The essence of 'goto logic' is that there is no return point to return to. In theory, procedure logic is stronger than simple goto logic, i.e. you can simulate an N statement program which uses gotos but not procedures with an O(N) statement program using procedures but no gotos, said procedure using program running in O(the execution time of the original program). Conversely there are programs using procedures which cannot be replaced by a program only using gotos without paying a penalty either in space or time. [The reason for this is that the return is actually a 'computed goto' which is stronger than the simple goto.] >>The prescription against goto's really means -- don't mix >>the two types of structure. >I think I agree with you (I'll have to ponder this a little while longer). It is worth mentioning that the reason for the stricture is that in 'goto logic' all control is at the same level. In truth, most real examples of goto logic are actually embedded goto logic, where there is a remembered return point that any 'goto block' can exit to. I.e. you put a state machine inside a block and exit the state machine by exiting the block. I have added comp.lang.misc to the group list and have directed followups there, because this is no longer particularly a C topic. -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.