[TUHS] Comments on "C"

Doug McIlroy doug at cs.dartmouth.edu
Thu Sep 8 22:35:28 AEST 2016


> After about 30 years of C, there are only three things I would
have liked to see:

> 1.  Computed goto

...

> Computed goto's are good for interpreters.

A computed goto, of course, is merely an optimized switch.
Dennis installed this optimization early in the evolution of C. The
main driving force was the performance and size of the PDP-11 Unix
kernel. As functionality grew, resource usage was repeatedly tamped
down by improving C's code generation.

The switch optimizer chose among three strategies: naive, binary
decision tree, and computed goto, depending on the number and density
of switch alternatives. Hybrid strategies may have been used, too,
but my memory is hazy on this point. In particular the optimization
improved system-call dispatch--thus achieving the objective,
"good for interpreters". I assume (I hope not unrealistically)
that this optimization has been in the repertoire of mainline C
compilers ever since.

> (Or perhaps require C to support tail recursion.)

I can imagine making a strong recommendation in the standard for
optimizing switches and (at least direct) tail recursion.

Doug


More information about the TUHS mailing list