baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
well i haven't been working with Inline module before and i find the cookbook a bit confusing. So could anyone help me figure this thing out. What i have is an array of numbers that i wish to pass into "rain()" function, print its elements and return the number 5.
use strict; my @v = (1,2,3,4); my $r = rain(\@v); print "$r\n"; use Inline C => <<'CC'; int rain(AV *a){ Inline_Stack_Vars; int i; for (i = 0; i < Inline_Stack_Items; i++) printf("%d\n",Inline_Stack_Item(i)); } Inline_Stack_Void; return 5; } CC
This code is obviously wrong. So, again, how do i do this ????

Thnx

Update:

also is it possible to omit this "Inline_Stack_Vars" and just use "a" as an array reference:

int rain(AV *a,int n){ // where n is the size of the array int i; for (i = 0; i < n; i++) printf("%d\n",a[i]); } return 5; }
Update:

yeap, ok, never mind, i was confused vith SV* and AV*
++ moritz

Replies are listed 'Best First'.
Re: InlineC problem
by moritz (Cardinal) on Oct 07, 2011 at 10:34 UTC

    Which part of the cookbook did you find confusing? Did you even read the relevant example?

    There's an example of how to use a list of arguments, and the discussion after it says that it's important to use the ellipsis syntax ... in this case. Yet you haven't used it.

    That example even prints the names from the argument list to STDOUT, which seems to be what you want; only the return statement needs to be modified.