gotos

Mark Purtill purtill at faline.bellcore.com
Mon Apr 18 09:11:25 AEST 1988


In article <> ajmyrvold at violet.waterloo.edu (Alan Myrvold) writes:
>Why do I use goto's ? 
>
>Because I believe that every function should have 
>exactly one entry point and exactly one exit point.
>
>Multiple RETURN statements are as bad as bad goto's -- i.e.
>the thread of the subroutine gets confusing.

First off, I find this claim dubious to say the least, especially
if many returns are error returns (eg:

	char *
get_foo( char *filename) { 	/* returns the foo or NULL on error */
	...
	if(( fp = fopen( filename, mode)) == NULL) {
		return (char *)NULL ;
		}
	...
	if( syntax error in the foo) return (char *)NULL ;
	...
	return foo ;
	}
).


In any case, I fail to see how replacing a "return" with a "goto" will
make it any less confusing, especially given that the label for the goto
may be on the next page, or that the next person to deal with the code
may add code after the label, etc.  All you've done is replace earlier
"return"s with "goto label"s which may not really do what you want.

^.-.^ Mark Purtill
((")) purtill at math.mit.edu



More information about the Comp.lang.c mailing list