logoalt Hacker News

WalterBrighttoday at 5:58 PM1 replyview on HN

> If you call via a function pointer, how do you supply the pointer to the data?

D has the notion of a "delegate", which is a (function pointer) and (context pointer) pair. This is incredibly useful, because delegates can:

1. call nested functions that need a pointer to the stack frame of the nestee function

2. call member functions that need `this` pointer

3. call lambdas

4. call COM member functions

The neato thing about this is the ABI for delegates is all the same, so a function that gets a delegate parameter will work with any of 1..4. It's one of the most used features of D.


Replies

klodolphtoday at 6:00 PM

Yes, that’s the “ABI” alternative that I was referring to.

show 1 reply