Table lookups - this is pretty definitive

Marco Leise Marco.Leise at gmx.de
Sat Apr 5 21:43:09 PDT 2014


Am Wed, 02 Apr 2014 18:05:32 -0700
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 4/2/2014 3:06 PM, bearophile wrote:
> > Walter Bright:
> >
> >> I don't see why not. Note that we couldn't do this for extern(C) functions, or
> >> variadics, or caller functions with parameters that need destruction, or
> >> parameters that may refer to any locals. That last constraint might be a
> >> doozy, however.
> >>
> >> Why not submit an enhancement request to bugzilla?
> >
> > So what does it happen if I (by mistake or by ignorance) try to use this on a
> > function that doesn't satisfy one of those requirements?
> 
> Then it won't tail call it.

How would `return foo(args)' be used in the C preprocessor example?
Would it be implemented like with a jump table?:

char c = ...;
return caseTable[c](args);

What are the benefits over "goto"? I figure with "goto" the
semantics are clearer and you can easily access the variables
on the stack. Does the TCO version enable any more use-cases?
(Note: I consider "far less convoluted code" a valid
use-case. :) )

-- 
Marco



More information about the Digitalmars-d mailing list