zentara provided an example of pass by reference. You can also pass by array - but, as with perl, C sees the argument list as one big array, not 2 separate arrays. So you need to supply the array sizes as arguments.

In the demo below, both arrays are the same size, so it's only necessary to supply one "size" argument.
use warnings; use Devel::Peek; use Inline C => <<'EOC'; AV * foo(SV * x, ...) { Inline_Stack_Vars; long array_size, i; AV * ret = newAV(); array_size = SvUV(Inline_Stack_Item(0)); /* check that array_size matches our expectations, based on the total number of arguments supplied */ if(Inline_Stack_Items != (2 * array_size) + 1) croak("Mismatch in number of arguments supplied to foo()"); /* for efficiency, make the array big enough in one fell swoop */ av_extend(ret, array_size - 1); /* multiply corresponding array elements and push the result into ret +*/ for(i = 1; i <= array_size; i++) av_push(ret, newSVnv(SvNV(Inline_Stack_Item(i)) * SvNV(Inline_Stack_Item(i + array_size))) +); return ret; } EOC my @num1 = (2.2, 3.3, 4.4,5.5); my @num2 = (6.6, 7.7, 8.8, 9.9); $arref = foo(scalar(@num1), @num1, @num2); print "@$arref\n"; # prints 14.52 25.41 38.72 54.45
If the values in the arrays are unsigned integers, replace SvNV with SvUV, and replace newSVnv with newSVuv.
If the values are signed integers, replace SvNV with SvIV, and replace newSVnv with newSViv.

Cheers,
Rob

In reply to Re: Arrays and Inline C by syphilis
in thread Arrays and Inline C by BobQQ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



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