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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue May 22 12:29:10 PDT 2012


On 5/22/12 1:14 PM, Steven Schveighoffer wrote:
> I agree, it's unsound. But so is this:
>
> int *blah = void;
>
> *blah = 5;
>
> It doesn't mean that the language should forbid it, or that the compiler
> isn't implemented as designed.

Initialization with void is a feature. My example shows the fail of a 
feature. There is no comparison.

> At the *very least*, the address to member function operation should be
> illegal in @safe code.

It should be verboten. Other means should be devised for achieving 
whatever utility is there.

>> At best things could be arranged that &Test.foo has type void
>> function(Test) or something.
>
> 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...

Very reasonable. Walter, could you please weigh in on this.


Thanks,

Andrei



More information about the Digitalmars-d mailing list