in reply to Interfacing a C program with Perl functions and modules

The following C code will return the array from an array reference.

AV* get_array(SV* aref) { if (! is_array_ref(aref)) croak("get_array() argument is not an array reference"); return (AV*)SvRV(aref); } int is_array_ref(SV* ref) { if (SvROK(ref) && SvTYPE(SvRV(ref)) == SVt_PVAV) return 1; else return 0; } SV* get_element(AV* array, int index) { SV **temp; temp = av_fetch(array, index, 0); if (!temp) { printf("Could not fetch element %d from array", index); croak("Ending program"); } else return *temp; }

Then, in another place in your C code you can use it like this:

/* dereference array and get requested arrayref */ array = get_array(aref); elem = get_element(array, index);

See AI::NeuralNet::Simple code for more information. I pass array references directly from Perl to C and back to Perl. I use Inline::C to make things easy.

Cheers,
Ovid

New address of my CGI Course.