in reply to Arrays and Inline C

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