7

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?

2 Answers 2

17

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"
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.