C programming: Dereferencing pointer to incomplete type error

前端 未结 5 748
春和景丽
春和景丽 2020-12-14 00:03

I have a struct defined as:

struct {
 char name[32];
 int  size;
 int  start;
 int  popularity;
} stasher_file;

and an array of pointers

5条回答
  •  感动是毒
    2020-12-14 01:02

    How did you actually define the structure? If

    struct {
      char name[32];
      int  size;
      int  start;
      int  popularity;
    } stasher_file;
    

    is to be taken as type definition, it's missing a typedef. When written as above, you actually define a variable called stasher_file, whose type is some anonymous struct type.

    Try

    typedef struct { ... } stasher_file;
    

    (or, as already mentioned by others):

    struct stasher_file { ... };
    

    The latter actually matches your use of the type. The first form would require that you remove the struct before variable declarations.

提交回复
热议问题