Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coping with C pointers to functions #188

Open
russel opened this issue Mar 19, 2018 · 4 comments
Open

Coping with C pointers to functions #188

russel opened this issue Mar 19, 2018 · 4 comments

Comments

@russel
Copy link
Contributor

russel commented Mar 19, 2018

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.

@jacob-carlborg
Copy link
Owner

Could you send please include the an example of how the declaration of the function looks like in the header file.

@russel
Copy link
Contributor Author

russel commented Mar 19, 2018

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);

@jacob-carlborg
Copy link
Owner

Can you include the exact declaration of check_frontend_t as well?

@russel
Copy link
Contributor Author

russel commented Mar 19, 2018

typedef int (check_frontend_t)(void *args, struct dvb_v5_fe_parms *parms);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants