Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C error Array: array type has incomplete element type.

Tags:

arrays

c

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?

like image 887
ambika Avatar asked Mar 18 '10 07:03

ambika


2 Answers

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"
like image 168
David Rodríguez - dribeas Avatar answered Sep 27 '22 16:09

David Rodríguez - dribeas


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).

like image 36
slartibartfast Avatar answered Sep 27 '22 16:09

slartibartfast