function -> delegate conversion (Re: On the richness of C++)

Bill Baxter dnewsgroup at billbaxter.com
Fri Apr 18 17:35:41 PDT 2008


Tomas Lindquist Olsen wrote:
> Walter Bright wrote:
>> Sean Kelly wrote:
>>> Sure, but templates don't suit every situation.  It's not uncommon for
>>> APIs to have to overload on accepting a function and a delegate for
>>> flexibility.
>>
>> The only way to merge function pointers with delegates is to have the 
>> compiler generate trampolines. This isn't very runtime efficient - the 
>> template approach will be faster.
> 
> I was reading about these a few days ago, as LLVM has support for these. 
> Basically it's also how GCC implements its nested function extension. I 
> figured someone else might find this link interesting!
> 
> There's a link to a paper on trampolines in the article linked as well:
> http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

So you mean if one uses GDC, then all calls to nested functions are 
handled using trampolines?  Or only if you take the address of a nested 
function and try to call that?

Anyway I totally don't see any problem with generating a trampoline in 
order to let a user assign a function pointer to a delegate pointer 
variable.  The people who are obsessed with the performance difference 
can make special cases for function pointers vs delegate pointers, but 
the rest of just go about our merry business.

--bb



More information about the Digitalmars-d mailing list