Update: I looked at this requirement post again: "In order to create a compact table for recording scores fast,....". What I wrote below about C isn't wrong. But I am now of the opinion that you don't even need C until you show otherwise... Please explain more about your app and why you think that you even need to interface with 'C'? What kind of benchmarks have you done? Do you need help on that part? Often the the right algorithm and data structure is more important than the raw speed of the language. So, I think now that you should explain why you even need 'C'?
end of update

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 */

In reply to Re: Passing a bytestring from Perl to Inline::C as a 2d array by Marshall
in thread Passing a bytestring from Perl to Inline::C as a 2d array by maasha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.