Callbacks in D as void functions

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 13 08:12:35 PST 2014


On Thursday, 13 November 2014 at 15:58:34 UTC, Wsdes wrote:
> void MyDtaCB(void* v){
>     // Do stuff
> }
>
> Events.OnData = cast(Callback) &MyDtaCB;

this compiles but might crash, the extern(C) is important on a 
callback to be used from a C program. I'd really recommend adding 
that to the function, even if you cast when assigning to the 
struct.


More information about the Digitalmars-d-learn mailing list