← Back to context

Comment by klodolph

14 hours ago

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

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