Explicitly unimplemented computed gotos

Iain Buclaw ibuclaw at ubuntu.com
Fri Nov 26 12:58:10 PST 2010


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> When I have suggested to add "computed gotos" (similar to the ones of GCC) to D,
Walter has answered that they need some work to be implemented, and they have
limited usefulness, almost only to optimize interpreters.
> But:
> - D is a system language, so writing interpreters is an important application of it.
> - I have found GCC computed gotos useful to speed up some of my code. Recently
even the CPython has introduced their usage in the main interpreter loop.
> - The GCC implementation of computed gotos is not standard for C and other
compilers may not understand it (to solve this trouble in GNU C code you need to
disable pieces of code, and this is less easy to do in D).
> So even if computed gotos are not going to be implemented in DMD I suggest to:
> 1) Invent a syntax to represent and use them (probably the GCC syntax is good,
because it's already known in C).
> 2) Make DMD understand this syntax, but refuse it at compile time (because DMD
doesn't support computer gotos).
> 3) Define a new standard Predefined Version, like "computed_goto" or
"Computed_goto" or something similar, that is defined if a D compiler supports
them (so DMD doesn't define it), that allows to disable the code that contains the
computed goto if a compiler doesn't support them.

I don't think this feature really warrants a new keyword.

Since we already have:

const var = 42;
switch (x) {
    case var:
        ...
    break;
}

Would only make sense to do the same for goto's.

goto *ptr;


Something that *would* warrant perhaps a new keyword would be non-local gotos, but
it's usefulness is very negligible...

Regards
Iain


More information about the Digitalmars-d mailing list