www.digitalmars.com         C & C++   DMDScript  

D - std.c.stdlib (atexit)

reply =?iso-8859-1?Q?Miguel_Ferreira_Sim=F5es?= <kobold netcabo.pt> writes:
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hi, again! i need some help... i am doing a singleton class (templated =
with Destructors).
the problem is that i don't know how to pass a D pointer to function to =
the c function atexit (std.c.stdlib)!!!

[compiler says: function atexit (void(C*)()) does not match argument =
types (void(*)()) ]

    private import std.c.stdlib;
    extern (C) int atexit(void (*)());

    interface IDestructor {
    public:
        void create(void (*dtor)());
    }

    class DestructorAtExit : IDestructor {
    public:
        void create(void (*dtor)()) { atexit(dtor); }
    }

thanks,
Miguel Ferreira Sim=F5es
Apr 07 2004
parent reply Carlos Santander B. <Carlos_member pathlink.com> writes:
In article <c51gsn$omq$1 digitaldaemon.com>,
=?iso-8859-1?Q?Miguel_Ferreira_Sim=F5es?= says...
hi, again! i need some help... i am doing a singleton class (templated =
with Destructors).
the problem is that i don't know how to pass a D pointer to function to =
the c function atexit (std.c.stdlib)!!!

[compiler says: function atexit (void(C*)()) does not match argument =
types (void(*)()) ]

    private import std.c.stdlib;
    extern (C) int atexit(void (*)());

    interface IDestructor {
    public:
        void create(void (*dtor)());
    }

    class DestructorAtExit : IDestructor {
    public:
        void create(void (*dtor)()) { atexit(dtor); }
    }

thanks,
Miguel Ferreira Sim=F5es
This works for me: private import std.c.stdlib; alias void function () c_func; extern (C) int atexit(c_func); interface IDestructor { public: void create(c_func); } class DestructorAtExit : IDestructor { public: void create(c_func dtor) { atexit(dtor); } } import std.c.stdio; void foo() { printf("bye"); } void main() { (new DestructorAtExit).create( &foo ); } ------------------- Carlos Santander B.
Apr 07 2004
parent "Miguel Ferreira Simões" <kobold netcabo.pt> writes:
thanks, it works!!!
Apr 07 2004