D - delegate with null this ?
- Mike Wynn (5/5) Sep 20 2003 Walker is there a way to do ...
 - Helmut Leitner (58/65) Sep 21 2003 As far as I remember, a delegate with this=null will crash (DMD 0.64?).
 
Walker is there a way to do ... fp = &((cast(foo)null).bar); where fp is a delegate, foo a class with a member `bar` ? i.e. end up with a delegate to a member function that will pass null for this.
 Sep 20 2003
Mike Wynn wrote:
 
 Walker is there a way to do ...
         fp = &((cast(foo)null).bar);
 where fp is a delegate, foo a class with a member `bar` ?
 
 i.e. end up with a delegate to a member function that will pass null for
 this.
As far as I remember, a delegate with this=null will crash (DMD 0.64?).
But you can add a dummy this to a function or method pointer.
Better be sure it will never use the dummy this.
All I know about delegates is in this module:
/*
** dg.d
** Copyright (C) 2003 Helmut Leitner
** Donated to Digital Mars.
** Released under the GNU GPL, see LICENSE.TXT
** and http://www.gnu.org/copyleft/gpl.html
*/
module venus.dg;
import venus.all;
alias void delegate () void_dg_void;
alias void delegate (...) void_dg_ellipsis;
alias void (*void_fp_void) ();
alias void (*void_fp_this) (void *);
alias void (*void_fp_ellipsis) (...);
struct DelegateStruct {
    void *pthis;
    void (*method)(void *pthis);
}
class DelegateHacker
{
    static DelegateHacker dh;
    static void *pthis;
    void method()
    {
    }
    void set_pthis()
    {
        pthis=this;
    }
    static this()
    {
        dh=new DelegateHacker;
        dh.set_pthis();
    }
    static void_dg_void FpRetDelegate(void_fp_void fp)
    {
        void_dg_void dg;
        ((DelegateStruct *)&dg).pthis=pthis;
        ((DelegateStruct *)&dg).method=(void_fp_this)fp;
        return dg;
    }
}
void_dg_void FpRetDelegate(void_fp_void fp)
{
    return DelegateHacker.FpRetDelegate(fp);
}
void_dg_ellipsis FpRetDelegate(void_fp_ellipsis fp)
{
    return (void_dg_ellipsis) DelegateHacker.FpRetDelegate((void_fp_void)fp);
}
-- 
Helmut Leitner    leitner hls.via.at
Graz, Austria   www.hls-software.com
 Sep 21 2003








 
 
 
 Helmut Leitner <helmut.leitner chello.at>