in reply to [OT: C] Getting pointers to functions
because I want to provide a perl wrapping for an mpfr function that takes a "pointer to function" as one of its arguments
Usually, the reason for passing a function pointer to another function is so the called function can either call the other function, or set up a call-back so something else (like an event handler) can call it.
That means you need to provide an address that is "local" to the function you are passing the pointer to.
With static linking, your XSubs will be in the same address space as the functions you want pointers to.
With dynamic linking, the addresses your Xsub will have will be "mapped" addresses. That is, addresses in the XSub's address space that it can use to call the functions in the DLL's address space.
I would suggest creating a C array of function pointers initialized to the addresses of the functions you need pointers for:
funcp FuncArray[] = { mpfr_mul, mpfr_read, /* etc */ }
Then your XSub can fetch the needed pointer by index.
To avoid having to figure out the indexes, you can use Perl to read the C source of FuncArray and create a hash with the function names as keys and indexes as values.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [OT: C] Getting pointers to functions
by syphilis (Archbishop) on Jan 05, 2017 at 08:18 UTC |