use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C'; typedef void (*hello_func_t)(SV * x); typedef SV * (*sv_func_t)(SV * x); void hola_mundo(SV * x) { printf("Hola, mundo! %d\n", (int)SvIV(x)); } SV * hola_mundo2(SV *x) { printf("Hola, mundo2! %d\n", (int)SvIV(x)); return newSViv((int)SvIV(x) * 2); } SV* get_hola_mundo_func_ptr() { return newSViv( PTR2IV(hola_mundo) ); } SV* get_hola_mundo2_func_ptr() { return newSViv( PTR2IV(hola_mundo2) ); } void do_hello(SV *sv_with_func_ptr, SV * x) { IV temp = SvIV(sv_with_func_ptr); hello_func_t hello = INT2PTR(hello_func_t, temp); hello(x); } SV * do_hello2(SV *sv_with_func_ptr, SV * x) { IV temp = SvIV(sv_with_func_ptr); sv_func_t hello = INT2PTR(sv_func_t, temp); return hello(x); } END_C my $num = 123458; my $func_ptr = get_hola_mundo_func_ptr(); do_hello($func_ptr, $num); my $func_ptr2 = get_hola_mundo2_func_ptr(); my $ret = do_hello2($func_ptr2, $num); print $ret;