Function pointer callback from C

Tyler Knott tywebmail at
Sun Feb 25 22:31:49 PST 2007

Mike Johnson wrote:
> Of course, I can pass void* data through the gpointer variable. But I 
> can't convert a class instance to an pointer... which would be really 
> *cough* cool *cough* :-) But maybe something else?

You can't convert /instances/, but you can cast any object /references/ to void 
pointers (because references are just pointers with syntactic sugar that hides 
all the details).  When you cast back from void* to a class type, D even checks 
to make sure it's a sane cast (the cast will return null if it's not sane).  The 
only caveat is that you're going to be careful to keep a reference to that 
object in memory the GC is aware of, otherwise it could get prematurely 
collected and cause weird runtime crashes.

More information about the Digitalmars-d-learn mailing list