Method pointers are *function* pointers?? Or delegates??

Steven Schveighoffer schveiguy at yahoo.com
Tue May 22 11:35:37 PDT 2012


On Tue, 22 May 2012 14:28:33 -0400, Jacob Carlborg <doob at me.com> wrote:

> On 2012-05-22 20:14, Steven Schveighoffer wrote:
>
>> I would suggest that it should be:
>>
>> function(Test this) with the 'this' being mangled into the name, and
>> affect the calling convention.
>>
>> Structs would be function(ref Test this).
>>
>> And const/shared/immutable decorations should apply properly to the
>> 'this' parameter.
>>
>> I'd wholeheartedly support such an improvement. In fact, I'd be willing
>> to write a DIP on it, if Walter had a chance of approving it. I just
>> don't know if it would happen...
>>
>
> It needs to be possible to compose delegates:
>
> class Foo
> {
>      void foo () {};
> }
>
> void delegate () dg;
>
> dg.funcptr = &Foo.foo;

Error, cannot cast function of type void function(Foo this) to void  
function(void *this)

dg.funcptr = cast(void function(void *this))&Foo.foo; // ok

> dg.ptr = cast(void*) new Foo;
> dg();
>
> At least it needs to be possible to do that in code marked with @system.
>

I think it should require a cast, regardless of the @system attribute, you  
are telling the type system a function that requires a Foo is now OK to  
accept a void *.  I don't think that's something we should accept  
implicitly.

-Steve


More information about the Digitalmars-d mailing list