C programming: Dereferencing pointer to incomplete type error

前端 未结 5 747
春和景丽
春和景丽 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 00:52

    You haven't defined struct stasher_file by your first definition. What you have defined is an nameless struct type and a variable stasher_file of that type. Since there's no definition for such type as struct stasher_file in your code, the compiler complains about incomplete type.

    In order to define struct stasher_file, you should have done it as follows

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

    Note where the stasher_file name is placed in the definition.

提交回复
热议问题