Evanovich has asked for the wisdom of the Perl Monks concerning the following question:
This seems to return a long number, not the desired number "1." Any suggestions?#! /usr/bin/perl -w use strict; use Inline C; sub MyFunc(\@); my $ref1 = [1,2,3,4,5]; my $ref2 = [6,7,8,9,10]; my @matrix; for (0..$#{$ref1}) { $matrix[0]->[$_] = ${$ref1}[$_]; } $_ = 0; for (0..$#{$ref2}) { $matrix[1]->[$_] = ${$ref2}[$_]; } MyFunc(@matrix); sub MyFunc (\@) { my $avMatrix= shift(@_); my $packedMatrix= ""; my @recycleBin; my $width= @{$avMatrix->[0]}; for my $avRow(@$avMatrix) { $width= @$avRow if @$avRow<$width; my $packedRow= pack("f$width", @$avRow); push @recycleBin, \$packedRow; $packedMatrix = pack("p", $packedRow); } return getangles(0+@$avMatrix, $width, $packedMatrix); } __END__ __C__ int getangles(int rows, int cols, char* packedMatrix) { int **M = (int **)packedMatrix; printf("Here I want the first entry of the matrix: %d", M); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sending packed arrays from Perl to C
by nardo (Friar) on Aug 06, 2001 at 09:45 UTC |