Patrick Dupre wrote: > Hello, > > I am trying to pass a array of references on array to a c subroutine: > my @set_2d = ([0.0, 1.0], [1.1, 2.2], [3.1, 4.4]) ; > test::test([EMAIL PROTECTED]) ; > > in xs I put: > > typedef double floatArray ; > > void * floatArrayPtr (int num) { > SV * mortal ; > mortal = sv_2mortal (NEWSV (0, num * sizeof (floatArray))) ; > return SvPVX (mortal) ; > } > > double > spectrum_2d (avref) > AV * avref > PREINIT: > int len, ncols; > int i, j ; > SV ** elem ; > floatMatrix *matrix ; > AV** row ; > CODE: > len = av_len (avref) + 1 ; > printf ("spectrum_2d: %d\n", len) ; > ncols = 2 ; > matrix = floatMatrixPtr (len) ; > for (i = 0 ; i < len ; i++) { > matrix [i] = floatArrayPtr (ncols) ; > } > for (i = 0 ; i < len ; i++) { > row = av_fetch (avref, i , 0) ; > if (row =! NULL) { > for (j = 0 ; j < ncols ; j++) { > elem = av_fetch (*row, j , 0) ; > if (elem == NULL) { > matrix [i] [j] = 0 ; > } > else { > matrix [i] [j] = SvNV (*elem) ; > } > } > } > } > RETVAL = 0 ; > OUTPUT: > RETVAL > > But it does not work, > If somebody could tell me what is wrong !
There are a few things wrong with this. There is no typedef for floatMatrix for instance, and =! isn't a valid C operator. But what is it supposed to do? It seems to be copying a Perl array of arrays to the floatmatrix 'matrix', but then just ignores that copy and returns 0.0. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/