Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
June 07, 2017 The reason for SIGSEGV function pointer problem | ||||
---|---|---|---|---|
| ||||
OK, so I have narrowed down my SIGSEGV problem to having no real idea how to do C function pointers in D code.
So I have a callback function that will be called from C library code. It currently has signature:
extern(C) int checkFrontend(void* _arguments, dvb_v5_fe_parms* frontendParameters)
because of the extern(C) I believe you have to use a type alias in
order to specify the type in function definitions. Hence:
alias check_frontend_t = extern(C) int function (void* args, dvb_v5_fe_parms* parms);
In the constructor of an object to abstract the result of a call to the C library code, the parameter is:
check_frontend_t* cf
in the creation of the object using the constructor, I am using the argument:
&checkFrontend
However. This gives me a type error:
extern (C) int function(void*, dvb_v5_fe_parms*)* cf
is not callable using argument type:
extern (C) int function(void*, dvb_v5_fe_parms*)
all the other arguments/parameters types match exactly, this is the only difference.
So why isn't &checkFrontend a thing of type check_frontend_t*?
--
Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
|
June 07, 2017 Re: The reason for SIGSEGV function pointer problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Wednesday, 7 June 2017 at 16:50:26 UTC, Russel Winder wrote:
> In the constructor of an object to abstract the result of a call to the C library code, the parameter is:
>
> check_frontend_t* cf
>
You should remove the pointer here...
/Paolo
|
June 07, 2017 Re: The reason for SIGSEGV function pointer problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote:
> So why isn't &checkFrontend a thing of type check_frontend_t*?
It's a thing of type `check_frontend_t`, which is a function pointer already. When you add an asterisk, you get a pointer to a function pointer.
|
June 07, 2017 Re: The reason for SIGSEGV function pointer problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote: > So why isn't &checkFrontend a thing of type check_frontend_t* AFAIK, you would usually translate: typedef int (check_frontend_t*)(void *args, struct dvb_v5_fe_parms *parms); into: alias check_frontend_t = extern(C) int function (void* args, dvb_v5_fe_parms* parms); The problem there is that libdvdv5 defines it as (check_frontend_t) and not (check_frontend_t*). To get around that you can ommit the * in the declaration of dvb_scan_transponder, and then you should be able to pass &checkFrontend to it. -- Mike Wey |
June 08, 2017 Re: The reason for SIGSEGV function pointer problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wey Attachments:
| Thanks also to Paolo Invernizzi and ag0aep6g for answering with a similar response. Using Mike's response as it has extra detail. On Wed, 2017-06-07 at 20:00 +0200, Mike Wey via Digitalmars-d-learn wrote: > On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote: > > So why isn't &checkFrontend a thing of type check_frontend_t* > > AFAIK, you would usually translate: > > > typedef int (check_frontend_t*)(void *args, struct dvb_v5_fe_parms > *parms); The C code in dvb-scan.h is actually: typedef int (check_frontend_t)(void *args, struct dvb_v5_fe_parms *parms); > into: > > alias check_frontend_t = extern(C) int function (void* args, > dvb_v5_fe_parms* parms); I can't remember what DStep produced initially, but the above is what I have in dvb_scan.d. Per se it seems consistent, but then functions in D, and their signatures, may be totally different to functions in C. > The problem there is that libdvdv5 defines it as (check_frontend_t) > and > not (check_frontend_t*). > To get around that you can ommit the * in the declaration of > dvb_scan_transponder, and then you should be able to pass > &checkFrontend > to it. I am now at the stage of wondering if I remember C semantics, C++ semantics, and D semantics for "pointers to functions". There may also be an issue of there being a bug in DStep… -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
Copyright © 1999-2021 by the D Language Foundation