Hi,

I'm wanting to get pointers to various mpfr library functions (because I want to provide a perl wrapping for an mpfr function that takes a "pointer to function" as one of its arguments). The following demo works fine, in so far as it goes:
use strict; use warnings; use Inline C => Config => LIBS => '-lmpfr -lgmp', BUILD_NOISY => 1; use Inline C => <<'EOC'; #include <mpfr.h> #define FUNC_PTR(x) newSViv(PTR2IV(x)) SV* get_mpfr_mul_func_ptr() { return newSViv(PTR2IV(mpfr_mul)); } SV * get_mpfr_add_func_ptr() { return newSViv(PTR2IV(mpfr_add)); } EOC print get_mpfr_mul_func_ptr(), "\n"; print get_mpfr_add_func_ptr(), "\n";
That gives me the numeric values of pointers to the mpfr_mul and mpfr_add functions, and I can readily construct the pointers to those functions from that info.

But the problem is that there's maybe 200 mpfr functions for which I would need to create pointers - and I'm not so sure that writing separate XSubs for each of those functions is the best way to proceed.
What would be good is to have a generic function that takes the name of the mpfr function as its argument, and then returns the pointer value of that mpfr function.
Something like:
SV * get_func_ptr(char * func_name) { /* code that returns the pointer value for the requested function */ }
But I don't know of any tricks that would allow that to happen.
What's the best approach here ... a C lookup table ?

Cheers,
Rob

In reply to [OT: C] Getting pointers to functions by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.