An amusing piece of code

aglew at ccvaxa.UUCP aglew at ccvaxa.UUCP
Sat Apr 19 10:34:00 AEST 1986


>At least in one case, jumping into blocks has been blessed by DMR,
>so I am not too worried about that.
Knuth too - converting a recursive program into a non-recursive one, ending
up with a jump into a the middle of a while loop. If this kind of thing
became common it would militate against architectures that have hardwired
loop-control stacks, etc.

>The problem with the goto versions is that one then has to think of a
>name for the label, and make sure one uses the same name in two places.
>Yuck-o!
If you were going to use a function, you wouldn't have to invent a name for
it? But, in general, I agree with you. The problem is that most languages
have very limited ways of generating names and scopes. I've always been
found of the label techniques Knuth uses in MIX, which was also used by at
least one UNIX assembler:
	1h: /* john */
	    goto 1f;	/* goes to mary */
	    goto 1b;	/* goes to john */
	1h: /* mary */
Ie. jumps can be designated as being either forward or back to the next
label `here' of the appropriate name in that direction. This makes reusing
names a lot easier (alphanumeric names should be allowed). However, funny
bugs can come in if you move code around, and suddenly find you're jumping
to the wrong label of the same name. Your editor should warn you if this
happens.

>Here is a suggested form that should satisfy the goto supporters, and
>still not make me have to think of a name for the label:
>
>#define GOTO_THERE      if(0){
>#define THERE           }
Please, no! If you look at this all you're doing is generating an anonymous
label.

Your switch solution is good, but might require extra variables,
particularly if the value of the switch variable is being changed. It also
requires extra switches. Now, I know it's not fashionable to worry about
speed, but some people do have to because their programs quite simply
stretch the most expensive machine that they can buy to its limits. I don't
want to condemn these people to having to code in assembler simply because a
high level language doesn't give them the clean, easy to implement
construct, like a goto, that they need to run that extra bit faster.

>-- ....
>Tim Smith       sdcrdcf!ism780c!tim || ima!ism780!tim || ihnp4!cithep!tim
>/* End of text from ccvaxa:net.lang.c */

Andy "Krazy" Glew. Gould CSD-Urbana.    USEnet:  ihnp4!uiucdcs!ccvaxa!aglew
1101 E. University, Urbana, IL 61801    ARPAnet: aglew at gswd-vms



More information about the Comp.lang.c mailing list