Newsgroups: comp.lang.misc Path: utzoo!utgpu!jarvis.csri.toronto.edu!csri.toronto.edu!vg From: vg@csri.toronto.edu (Victor Greenberg) Subject: Passing Values Through a "goto" Message-ID: <8901070434.AA10471@yorkville.csri.toronto.edu> Organization: University of Toronto, CSRI References: <3300001@uxg.cso.uiuc.edu> <3290002@hpctdls.HP.COM> <4505@xenna.Encore.COM> <2583@ficc.uu.net> <9310@ihlpb.ATT.COM> <11359@haddock.ima.isc.com> Date: Fri, 6 Jan 89 23:34:00 EST karl@haddock.ima.isc.com (Karl Heuer) writes: >Let's try to define EC, an extension of C with the property that every >statement is an expression, yet retaining the property that every expression >has a type. All constructs with no reasonable value definition become void >expressions. >... I once designed an expression-based variant of C called "D". This language supported "compound expressions" of the form: ( [expression|declaration] ; ... ; expression ) The final expression yields the result. This means you can embed declarations within expressions: ( int i = getint(); i * i ) A compound expression with no declarations has the form: ( expr1; expr2; ...; exprn ) and yields exprn as its result. This means that the "," operator is unnecessary, as ";" can be used in its place. A compound expression with a missing result expression has a value of type "void". Eg: ( expr1; expr2; expr3; ) This means we don't need C's compound statements enclosed in {}, we can use parentheses instead. [None of this is new. Algol 68 already does all of the above. I wish C were as well designed.] >Passing values through a goto doesn't seem to work well, since a label by >itself is not a valid statement. Well, I guess we could say that a labeled >null statement has the value of the statement preceding the goto, but that's >stretching the idea a bit too far, I think. Although goto is questionable as a language feature, it isn't hard to generalize for use in an expression based language. Instead of labelled statements, you want labelled *expressions*. For example: printf("%d\n", foo:(a+b) * c) In the above fragment, (a+b) is a sub-expression with the label "foo". When this fragment is executed normally, the value printed is (a+b) * c. However, elsewhere in the program, you can write: goto foo(x) This will jump into the middle of the call to printf, and the value printed is x * c. Doug Moen.