在C中取消引用指向不完整类型(具有明确定义的结构)的指针

Joe*_*aci 1 c struct pointers dereference

我知道至少有10个问题已经存在,但它们都指向了我没有做的事情.

在头文件中我有......

typedef struct Node {
   struct Node *next;
   struct pgmap page;
} Node;

typedef struct linkedlist {
struct Node *head_ptr;
struct Node *tail_ptr;
} LList;
Run Code Online (Sandbox Code Playgroud)

在我的c文件中我有

struct LList mainList;

int main()
{
    struct LList *root;
    root = &mainList;
    root->head_ptr = NULL;
    root->tail_ptr = NULL;
    ...
}
Run Code Online (Sandbox Code Playgroud)

在root->行上,我得到解除引用ptr ...错误.已经在这里的所有线程都指出了人们不小心创建匿名结构的问题,例如

typedef struct{
    int a;
}; monkey
Run Code Online (Sandbox Code Playgroud)

代替

typedef struct monkey{
    int a;
}; monkey
Run Code Online (Sandbox Code Playgroud)

那我错过了什么?

jwo*_*der 10

没有称为" struct LList"的类型.代码" typedef struct linkedlist { ... } LList;"创建两个类型名称:一个是struct linkedlist,另一个是LList(没有" struct").因此,您需要将" struct LList" 更改为" LList."