gotos

Peter J Desnoyers peter at athena.mit.edu
Sun Apr 17 12:57:01 AEST 1988


In article <751 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>When your optimizing compiler can convert case switches with case numbers 
>generated into the more efficient code such as I would write, I will consider
>eliminating those gotos. 

I don't know about optimizing compilers, but I've heard horror stories
of non-optimizing compilers using jumptables for switch statements.
(Oh no!! Why does "switch (n) {case 0: foo(); case 20000: bar();}" generate
an 80k executable?) It may have been an older VMS compiler. I dunno...

Personally, I think that doing such grevious harm to the source code
in the name of 'optimizing' is off the mark. The time spent writing
and maintaining that code could have been spent (1) buying an
optimizing compiler; (2) writing it in assembler; or (3) convincing
your boss to spring for a faster machine. 

Perhaps a better thing than docking people's pay for 'goto's would be
a compiler that put a delay in with every goto. Ten or twenty nop's
should be about right. Then people would only use goto when it was
really needed for stylistic reasons.

btw, my favorite reason for using goto - to cope with the problem that
the same word (break) is used to terminate loops and to signal the end
of a section of a switch. Thus you can write "if (foo) break;", but
you may have reason to write:
					(what you want to write: )
  while (foo)				while (foo)
    switch (bar)			  switch (bar)
    {					  {
      case n: 				    case n:
	goto (end_while); 		      break;
	break;				      esac; /* or whatever */
    }					  }
  end_while:

				Peter Desnoyers
				peter at athena.mit.edu



More information about the Comp.lang.c mailing list