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
  • 398,947
  • 96
  • 818
  • 769
Rayne
  • 14,247
  • 16
  • 42
  • 59

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
  • 22,018
  • 3
  • 52
  • 103
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
  • 142,963
  • 15
  • 272
  • 331
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,381
  • 3
  • 22
  • 26