C array of strings referenced by const GLchar **
i have a C function that requires to be called with a "const GLchar **" parameter.

I am not a C programmer by trade (perl is my game) but i am trying to call a C library from perl. I have all the other required functions wrapped (SWIG). This is the last troublesome one.
Please dont shoot me down for my (lack of) C skills. I am trying and google only helps if you know exactly what to type!

i understand that "const GLchar **" means that it wants a pointer to an array of strings (GLchar arrays).
with no way of creating that directly i have to create a GLchar array first:

        GLbyte *GLbyte_array(int size) {
          return (GLbyte *) malloc(sizeof(GLbyte)*size);
        }

so i use that in perl via:

        my $var=GLbyte_array(20);

and then populate that one char at a time from perl by calling:

       void GLbyte_put(GLbyte *a, int i, char val) {
         a[i] = val;
       }

again, perl:

        my $str="hello";
        for(my $i; $i<length($str); $i++)
        { GLbyte_put($var, $i); }

all good. (well, perhaps not good - but it works).
i have a C char array containing the word "hello".

my solution then was to attempt to build an array of these guys and drop the array i created above into it. then return my required pointer to it:

        const GLchar **get_GLbyte_array_ptr(GLbyte *a) {
	     char *arr[1];
	     arr[0]= a;
	     return (const GLchar**)arr[0];
       }

perl:

        my $ptr=get_GLbyte_array_ptr($var);

this is clearly a load of tosh. it compiles and then segfaults.

can you recommend alternate code/fixes for the problem.

and yes, i really do know that i dont know C - so i humbly request constructive responses rather than the abuse i deserve.

cheers

dch
C array of strings referenced by const GLchar **
===

i have a C function that requires to be called with a "const GLchar **" parameter.

I am not a C programmer by trade (perl is my game) but i am trying to call a C library from perl. I have all the other required functions wrapped (SWIG). This is the last troublesome one.
Please dont shoot me down for my (lack of) C skills. I am trying and google only helps if you know exactly what to type!

i understand that "const GLchar **" means that it wants a pointer to an array of strings (GLchar arrays).
with no way of creating that directly i have to create a GLchar array first:

        GLbyte *GLbyte_array(int size) {
          return (GLbyte *) malloc(sizeof(GLbyte)*size);
        }

so i use that in perl via:

        my $var=GLbyte_array(20);

and then populate that one char at a time from perl by calling:

       void GLbyte_put(GLbyte *a, int i, char val) {
         a[i] = val;
       }

again, perl:

        my $str="hello";
        for(my $i; $i<length($str); $i++)
        { GLbyte_put($var, $i); }

all good. (well, perhaps not good - but it works).
i have a C char array containing the word "hello".

my solution then was to attempt to build an array of these guys and drop the array i created above into it. then return my required pointer to it:

        const GLchar **get_GLbyte_array_ptr(GLbyte *a) {
	     char *arr[1];
	     arr[0]= a;
	     return (const GLchar**)arr[0];
       }

perl:

        my $ptr=get_GLbyte_array_ptr($var);

this is clearly a load of tosh. it compiles and then segfaults.

can you recommend alternate code/fixes for the problem.

and yes, i really do know that i dont know C - so i humbly request constructive responses rather than the abuse i deserve.

cheers

dch