C callbacks?

BCS ao at pathlink.com
Wed Mar 18 11:30:34 PDT 2009


Reply to Chris,

> I've hit another snag on my C library interfacing.  The .h defines a
> function:
> 
> //typedef bool (*TCOD_bsp_callback_t)(TCOD_bsp_t *node, void *userData);

In C read this as: pointer to function taking ... (stuff) and returning bool

in D the more normal way to write that would be:

typedef bool function(bsp_t* node, void* userData) TCOD_bsp_callback_t;

if you are passing this to C code you will need an exter(C) in there somewhere.

> bool* bsp_callback_t(bsp_t* node, void* userData); //bsp_t is a struct 
defining the bsp tree
> 
> Sidenote: Did I translate that right?
> 

Try it, test it, beat the snot out of it. If it works it's likely correct.

> Anyway, this function is later passed into various functions, like:
> 
> bool bsp_traverse_pre_order(bsp_t *node, bsp_callback_t listener, void
> *userData);
> 
> I've tried doing some reading on this board regarding c callbacks and
> delegates, but it feels a bit over my head.  Can anyone assist me in
> figuring out how to D-ify this bit of code so I can interact with the
> C dll?
> 

C code and delegates are incomparable but C and function pointers are not.




More information about the Digitalmars-d-learn mailing list