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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.