in reply to Passing a bytestring from Perl to Inline::C as a 2d array
I don't know the answer to the Perl<->C interface question. But your C code looks strange to me.
I have no idea what this "foo" and "bar" stuff is about. In C, practical 2-D arrays are built as array of pointer to "type" and that pointer array is NULL terminated. In this case, pointer to pointer to char. The "built-in" C 2D array is pretty much worthless in practical applications.
Anyway what you are describing from the C point of view is like exactly like "argv". I don't see how your C code even compiles! This is a Perl forum, but I would think a first step to interface Perl and C together is to be able to write working C code! Below, dump_strings() will dump "argv" or the "data" structure.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { void dump_strings( char **byte_strings ); char *data[] = {"some stuff", "more stuff", "and third stuff", NULL }; dump_strings(data); dump_strings(argv); exit(0); } void dump_strings ( char **byte_strings ) { for ( ; *byte_strings; byte_strings++) { printf ("%s\n",*byte_strings); /* a per char loop would go here */ } } /* prints: some stuff more stuff and third stuff */
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing a bytestring from Perl to Inline::C as a 2d array
by Porculus (Hermit) on Nov 12, 2009 at 00:13 UTC | |
by Marshall (Canon) on Nov 12, 2009 at 06:48 UTC |