Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!rochester!pt!ius1.cs.cmu.edu!edw From: edw@ius1.cs.cmu.edu (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: goto's and switch statements -- mild proposal Message-ID: <1035@ius1.cs.cmu.edu> Date: Wed, 12-Aug-87 21:20:04 EDT Article-I.D.: ius1.1035 Posted: Wed Aug 12 21:20:04 1987 Date-Received: Sat, 15-Aug-87 05:02:42 EDT References: <855@tjalk.cs.vu.nl> <2683@hoptoad.uucp> <916@haddock.ISC.COM> <930@haddock.ISC.COM> Organization: Carnegie-Mellon University, CS/RI Lines: 50 Summary: y In article <930@haddock.ISC.COM>, karl@haddock.ISC.COM (Karl Heuer) writes: > [Context: karl@haddock suggested that switch labels should behave more like > normal labels; and that the latter should have to be declared, giving them > block scope; and a bunch of related ideas.] > > In article <1032@ius1.cs.cmu.edu> edw@ius1.cs.cmu.edu (Eddie Wyatt) writes: > >Consider the problems "goto case N" cause when there are two switch > >statements each with a case N label in the function block. > > The solution is for the scope of a switch label to be the switch statement > itself. Thus in the example posted in another article by ron@topaz, you get > an error message from the compiler. If the switch statements are nested, you > get the innermost enclosing one. > > >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. > > I don't see that this is any worse than the current situation with variables: > "{ int i; ... { double i; ... i=0; } }". In fact, by removing the special > case (currently, labels are the only things that have function scope) it's > possible that this would simplify the compiler. > The problem I was describing here is the one where you have two switch statements not nested with case labels N. If you where to support a label's scope extending over to the whole function block then you have a different type of problem than the one you have described above. The scope of double i does not extend accross the whole function, only the block that it is defined in, a much simplier situation to deal with. If you where to restrict the scope of the label to the switch statement which it is defined in then the problem of uniquely defining the case label is analogous to uniquely defining nested variable declarations. But if you only support a label's scope over the switch statement it is defined in then you have introduced a non-orthogonal feature into the language since C label definitions extend over the whole function block, not just the block they are defined in. > Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu