Member function pointers

Manu turkeyman at gmail.com
Mon Jun 10 00:23:19 PDT 2013


On 10 June 2013 16:50, Jacob Carlborg <doob at me.com> wrote:

> On 2013-06-08 01:21, Manu wrote:
>
>> So from my dconf talk, I detailed a nasty hack to handle member function
>> pointers in D.
>> My approach is not portable, so I'd like to see an expression formalised
>> in D, so this sort of interaction with C++ is possible, and also it may
>> be useful in D code directly.
>>
>> I'm thinking something like this... Keen to hear thoughts.
>>
>> My approach was this:
>>    void function(T _this, ...args...);
>>
>> Explicit 'this' pointer; only works with ABI's that pass 'this' as the
>> first integer argument.
>>
>> What I suggest is:
>>    void function(T this, ...args...);
>>
>> Note, I use keyword 'this' as the first argument. This is the key that
>> distinguishes the expression as a member-function pointer rather than a
>> typical function pointer. Calls through this function pointer would know
>> to use the method calling convention rather than the static function
>> calling convention.
>>
>> For 'extern(C++) void function(T this)', that would be to use the C++
>> 'thiscall' convention.
>>
>> I think this makes good sense, because other than the choice of calling
>> convention, it really is just a 'function' in every other way.
>>
>
> Can't we just say that a delegate declared as extern(C++) is a member
> function?


That seems pretty awkward to me. Basically a hack.
A function pointer is not a delegate, so I don't see why that should be
used to describe one.
Also, extern(C++) delegates are useful too in their own right

Or do you want to use member functions without connecting to C++ as well?


I haven't needed to yet... but that doesn't mean it might not be useful.
It would probably be used in D for tight binding with other systems.
AngelScript binds to native code with member function pointers... just off
the top of my head.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130610/86e2e581/attachment.html>


More information about the Digitalmars-d mailing list