tags:

views:

1013

answers:

2

Hi

my code

extern int docx(char *,char[][]) // in a header file

it is compiled in solaries properly.

but in redhat linux it shows bellow error.

array type has incomplete element type.

i know i can solve it as - char[][20]

is it the right way.

+4  A: 

You will have to know what the function is actually expecting and modify the interface accordingly. If it is expecting a bidimensional array (char [N][M]) the correct interface would be:

extern int docx(char *,char*[M]);

Which is different from:

extern int docx( char*, char** );

In the first case the function would be expecting a pointer into a contiguous block of memory that holds N*M characters (&p[0][0]+M == &p[1][0] and (void*)&p[0][0]==(void*)&p[0]), while in the second case it will be expecting a pointer into a block of memory that holds N pointers to blocks of memory that may or not be contiguous (&p[0][0] and &p[1][0] are unrelated and p[0]==&p[0][0])

// case 1
ptr ------> [0123456789...M][0123.........M]...[0123.........M]

// case 2
ptr ------> 0 [ptr] -------> "abcde"
            1 [ptr] -------> "another string"
              ...
            N [ptr] -------> "last string"
David Rodríguez - dribeas
thank you.you provide a good material.
ambika
A: 

char *[M] is no different from char **. char *[M] is an array of pointers to char. The dimension plays no role in C (in this case). What David meant was char (*)[M] which is a pointer to an array of M chars which would be the correct type for your prototype - but your char [][M] is fine also (in fact it is the more common formulation).

slartibartfast