dstep
dstep copied to clipboard
Coping with C pointers to functions
Playing with libdvbv5 still: I am having a problem with function pointers. In the C code a function is declared:
dvb_v5_descriptors* dvb_scan_transponder (
dvb_v5_fe_parms* parms,
dvb_entry* entry,
int dmx_fd,
int function () check_frontend,
void* args,
uint other_nit,
uint timeout_multiply);
however, the check_frontend
project has to be a function with signature:
int function (void* args, dvb_v5_fe_parms* parms)
there is a type check_frontend_t
but the declaration of dvb_scan_transponder
seems not to use it, which is very C obviously. It means though I end up with the error:
../../Repositories/Git/Masters/DVBTune/source/libdvbv5.d(139): Error: function dvb_scan.dvb_scan_transponder (dvb_v5_fe_parms* parms, dvb_entry* entry, int dmx_fd, extern (C) int function() check_frontend, void* args, uint other_nit, uint timeout_multiply) is not callable using argument types (dvb_v5_fe_parms*, dvb_entry*, int, extern (C) int function(void* args, dvb_v5_fe_parms* parms), void*, uint, uint)
For which D seems to offer no solution since cast(extern (C) int function())
is not a valid cast.
Obviously the hack of the moment is to manually change the declaration, but I suspect the solution is to correct the upstream source. I guess I am flagging this in case someone knows a workaround.
Could you send please include the an example of how the declaration of the function looks like in the header file.
The C header file declaration of the function is:
struct dvb_v5_descriptors *dvb_scan_transponder(struct dvb_v5_fe_parms *parms,
struct dvb_entry *entry,
int dmx_fd,
check_frontend_t *check_frontend,
void *args,
unsigned other_nit,
unsigned timeout_multiply);
so I am now wondering why the post dstep declaration is:
dvb_v5_descriptors* dvb_scan_transponder (
dvb_v5_fe_parms* parms,
dvb_entry* entry,
int dmx_fd,
int function () check_frontend,
void* args,
uint other_nit,
uint timeout_multiply);
Can you include the exact declaration of check_frontend_t
as well?
typedef int (check_frontend_t)(void *args, struct dvb_v5_fe_parms *parms);