logoalt Hacker News

klodolphtoday at 5:45 PM2 repliesview on HN

It’s not a question of ISA support. If you call via a function pointer, how do you supply the pointer to the data? (It has to either be in a separate place from the function code, or the same place. One requires an ABI change, the other an executable, writable section of memory.)


Replies

WalterBrighttoday at 5:58 PM

> 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.

show 1 reply
QuadmasterXLIItoday at 6:22 PM

but that can just be executable heap?

show 1 reply