The final word on GOTO (Don't I wis

Herman Rubin cik at l.cc.purdue.edu
Fri Oct 13 23:26:52 AEST 1989


In article <566 at sunquest.UUCP>, ggg at sunquest.UUCP (Guy Greenwald) writes:
< In article <6490 at ficc.uu.net|, peter at ficc.uu.net (Peter da Silva) writes:

			.....................
	
< | Really:
< | 	case whatever:
< | 		special-code...;
< | 		goto common;
< | 
< | Is a lot clearer than:
< | 	case whatever:
< | 		special-code...;
< | 		common(a, whole, bunch, of, random, arguments);
< | 		break;
< | -- 
< | Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation
< | Quote: Structured Programming is a discipline -- not a straitjacket.
> 
> If the arguments are really random, how can the function work? They
> can't just be chosen at random. As to their number, it depends on how
> many arguments the function needs. Regarding local variables, you know 
> very well that C can have external variables. I think that no one is going
> to win this argument against you because you're going to come up with
> contrived rebuttals no matter what anyone says. If goto's have a place
> in C, you haven't made a "case" for them.
> 
> /* Really: */
> 	case whatever:
> 		special-code...;
> 		goto common;
> /* Is no clearer than: */
> 	case whatever:
> 		special-code...;
> 		common();
> 		break;

One problem with the function call is that, as da Silva writes, there can
be a lot of other variables being used.  It can be quite difficult to manage
the implicit passage of arguments that Greenwald is assuming away.

There are other problems.  The cost of a subroutine call is necessarily
considerably greater than that of a transfer.  Furthermore, the first block
of code indicates that, at the termination of common, the program continues
from that point and does not do a return to the place from which it is called.
I find this rather a common situation, and have not seen an alternative to
the goto for this situation which is not horribly expensive and less clear.
Also, at the continuation, the "whole bunch of random arguments" is still
there for the rest of the program to use (or use as modified by common).
This is not provided for by a call.
-- 
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907
Phone: (317)494-6054
hrubin at l.cc.purdue.edu (Internet, bitnet, UUCP)



More information about the Comp.lang.c mailing list