简体   繁体   中英

error: array type has incomplete element type - already defined structs

extern  const   struct  ss_type     ss_table    [MAX_CLASS];
extern  const   struct  ss_group_type   ss_group_table  [MAX_GROUPS];

merc.h:4430:30: error: array type has incomplete element type merc.h:4431:35: error: array type has incomplete element type

Working on a pet project and am completely stumped on this one. I don't really have an idea of why this error would reflect these lines. My best guess would be that the compiler can't make sense of what ss_table, ss_type, ss_group_table, and ss_group_type are.

However, ss_table and ss_type are defined

const struct ss_type    ss_table [MAX_CLASS] =  {   {   /* FALSE */  
"",     
{0},    
{0},    
{NULL}  
},

So are ss_group_table and ss_group_type

const struct ss_group_type  ss_group_table [MAX_GROUPS] = 
{
  /* NONE: FALSE return 0 */
  {"", 0,
   {
     {NULL, 0, 0,   {NULL},    {NULL}  }
   }
  },

which puts me at a loss for how to resolve this error.

No, type has only be forward-declared, but not been specified. At least you didn't give us any. A resl definition like

struct toto {
  double hei;
};

must be visible.

Such struct definitions should be put in a header file .h and be included in .c files (co called compilation units) to make the definitions visible.

If the type is incomplete, it means that the it has been forward-declared, but has not yet been declared fully.

For example, the following compiles:

struct S1 {};
struct S1 arr1[10];

whereas the following doesn't:

struct S2;
struct S2 arr2[10]; /* error: array type has incomplete element type */
struct S2 {};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM