The final word on GOTO (Don't I wis

Peter da Silva peter at ficc.uu.net
Wed Oct 4 00:42:18 AEST 1989


The last time I looked at a stdio library there was a goto in _doprnt:

	if you see a %
	handle number.number stuff
	see what the format is

	switch(format) {
		case 'd':
			base = 10;
			if(number < 0) {
				sign = '-';
				number = -number;
			} else
				sign = 0;
			...
			goto donum;
		case 'u':
			base = 10;
			sign = 0;
			...
			goto donum;
		case 'o':
			base = 8;
			sign = 0;
			...
			goto donum;
		case 'x':
			base = 16;
			sign = 0;
			...
			goto donum;
		donum:
			format number with base, sign, etc.

(yes, I know this won't work for -32768. It's just an example)

You could probably rearrange this to not need the gotos, but I really
don't see that it would make the code any clearer. That's the problem.
Sometimes just leaving the goto in makes the code easier to read.
Really. A goto isn't the devil, it's just a seldom used ingredient.
Like blue food coloring... you don't use it often, but would you ban
it from the kitchen?
-- 
Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation.
Biz: peter at ficc.uu.net, +1 713 274 5180. Fun: peter at sugar.hackercorp.com. `-_-'
"That is not the Usenet tradition, but it's a solidly-entrenched            U
 delusion now." -- brian at ucsd.Edu (Brian Kantor)



More information about the Comp.lang.c mailing list