On Fri, Jun 12, 2009 at 10:49 PM, Patrick Dupre <pd...@york.ac.uk> wrote:

>
> To pass an integer, I use to make a newSViv.
> How do I do to pass a int* ?
>
> Perhaps not exactly what you're after ... hope it helps:

##########################################
use warnings;
use Inline C => Config =>
    BUILD_NOISY => 1;

use Inline C => <<'EOC';

void foo(SV * x) {
     int i = SvIV(SvRV(x));
     printf("%d\n", i);
}

SV * bar() {
     int i, *iptr;
     SV *obj_ref, *obj;
     iptr = &i;
     i = 1234567;
     obj_ref = newSV(0);
     obj = newSVrv(obj_ref, NULL);
     sv_setiv(obj, *iptr);
     SvREADONLY_on(obj); /* optional */
     return obj_ref;
}

EOC

$x = 173;
foo(\$x);

$ref = bar();
print $$ref, "\n";

##########################################

Outputs:
17
1234567


Cheers,
Rob

Reply via email to