Hi Jin,

I don’t think you can access perl variables this way because your C function 
needs some sort of reference to them. Change your code to,

$data = "this is a test";
test($data);

use Inline C => <<'END_OF_C_CODE';

void test(SV* data) {
        printf("here: %s\n", SvPV(data, PL_na));
}

END_OF_C_CODE

Cheers,
Ron.

> On 23 Nov 2016, at 1:29 pm, Perf Tech <perfte...@gmail.com> wrote:
> 
> Dear expert,
> 
>    I am trying to access perl global variable ($data in this case) from 
> within a inline C function, but the "data" variable I used is not defined.
> Any idea how to do it?
> 
> Thanks
> Jin
> 
> 
> $data = "this is a test";
> test();
> 
> use Inline C => <<'END_OF_C_CODE';
> 
> void test() {
>       printf("here: %s\n", SvPV(data, PL_na));
> }
> 
> END_OF_C_CODE
> 

Reply via email to