Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!ptsfa!ihnp4!cuae2!killer!molly From: molly@killer.UUCP Newsgroups: comp.lang.c Subject: Re: goto's and switch statements -- mild proposal Message-ID: <1335@killer.UUCP> Date: Fri, 14-Aug-87 04:42:05 EDT Article-I.D.: killer.1335 Posted: Fri Aug 14 04:42:05 1987 Date-Received: Sun, 16-Aug-87 08:42:27 EDT References: <855@tjalk.cs.vu.nl> <2683@hoptoad.uucp> <916@haddock.ISC.COM> <1032@ius1.cs.cmu.edu> Organization: The Unix(tm) Connection, Dallas, Texas Lines: 67 Summary: The label table already has plenty of info about the case labels In article <1032@ius1.cs.cmu.edu>, edw@ius1.cs.cmu.edu (Eddie Wyatt) writes: > In article <916@haddock.ISC.COM>, karl@haddock.ISC.COM (Karl Heuer) writes: > > In article <2683@hoptoad.uucp> gnu@hoptoad.uucp (John Gilmore) writes: > > >What bothers me is that I can't say ["goto default" and "goto case N"]. > > Consider the problems "goto case N" cause when there are two switch > statements each with a case N label in the function block. > > Also just consider how you would implement the two switch statements > each with a case N label. Since each label is a posible target of > a goto, it must be put into a label table for that function block. > Now you have multiple defined labels (label N) unless you do a few > ugly things to uniquely define each label - but then look up on > labels become more expensive. The case statement labels already have to go into a label table to keep track of what values have been entered so the default can be handled correctly. Some compilers generate more than one type of code to handle a switch. The first variety of code is the cmpl #value,d0 beq label and the next is the word array (kinda maybe like ...) subl #smallest,d0 cmpl #largest-smallest,d0 bgt default addl d0,d0 movw 6(pc,d0),d0 jmp 2(pc,d0:w) .word label1 .word labelN and so on. You can't discard the switch label info until the `}' that closes the switch statement if you are generating code in this fashion. (I invent a label that will appear after the last code from the switch and jump there so I can defer the descision - I always hold onto my switch tables) The big bastard in this plan is the multiple labels. You could add a flag `Number of default: labels in this block' and allow goto default; as a statement. Or you might even allow it to be syntactically legal inside of a switch. Now that would be useful, except it's too easy already. But then, the goto case N is also easy - N = function to get value; goto_case_N; switch (N) { . . . } N = some new value; goto goto_case_N; Now that's an example of bogus code. Molly -- Molly Fredericks UUCP: { any place real }!ihnp4!killer!molly Disclaimer: Neither me, nor my cat, had anything to do with any of this "I love giving my cat a bath, except for all those hairs I get on my tongue" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~