I have:
extern int docx(char *,char[][]) // in a header file
It is compiled properly in solaris, but in Redhat Linux it shows the error bellow:
array type has incomplete element type.
I know i can solve it as - char[][20]
Is it the right way?
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"
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With