簡體   English   中英

在C中解引用指向不完整類型(具有明確定義的結構)的指針

[英]Dereferencing pointer to incomplete type(with well defined structs) in C

我知道已經至少有10個問題,但這都指向我沒有做的事情。

在頭文件中,我有...

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

typedef struct linkedlist {
struct Node *head_ptr;
struct Node *tail_ptr;
} LList;

在我的C文件中

struct LList mainList;

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

在root->行上,我得到解引用ptr ...錯誤。 此處已存在的所有線程都指出了一個問題,人們意外地創建了匿名結構,例如

typedef struct{
    int a;
}; monkey

代替

typedef struct monkey{
    int a;
}; monkey

那我想念什么????

沒有名為“ struct LList ”的類型。 代碼“ typedef struct linkedlist { ... } LList; ”創建兩個類型名稱:一個是struct linkedlist ,另一個是LList (不帶“ struct ”)。 因此,你需要改變“ struct LList ”到“ LList 。”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM