0

I have a global array of structure declared as

struct _links link[255][255][255];

in my main.c. This array of structures is also used in another file, action.c, and I tried to declare it in action.c as an extern, i.e.

extern struct _links link[255][255][255];

However, I got the error message "array type has incomplete element type". I don't understand what that means. How can I resolve this problem?

Thank you.

skaffman
  • 390,936
  • 96
  • 800
  • 764
Rayne
  • 13,285
  • 15
  • 38
  • 49

3 Answers3

5

Define your structure struct _links in a header file; include that in both my_main.c and action.c, compile them seperately and link them.

It works without header file for in-built data types. but for user defined data types, header file is needed.

pmdj
  • 19,862
  • 2
  • 49
  • 100
sekhy
  • 66
  • 1
  • Note that the main reason for this is that the compiler can't know the size and alignment of the array elements in action.c without a complete definition of `struct _links`. – pmdj Jan 17 '12 at 12:04
2

You have to declare a type struct _links somewhere.

ouah
  • 138,975
  • 15
  • 262
  • 325
1

a good programming practice is to create a new file links.h which contains

extern struct _links link[255][255][255];

include this file on both main.c and action.c .

do not forget to define the variable only once.

for more informations about extern keyword,take a look at this post https://stackoverflow.com/a/1433387/1117720

Community
  • 1
  • 1
Amine Hajyoussef
  • 4,371
  • 3
  • 20
  • 25