简体   繁体   中英

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

I know there are at least 10 questions already about this, but they all point to something I am not doing.

In a header file I have...

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

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

In my c file I have

struct LList mainList;

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

On the root-> lines I get the dereferencing ptr... error. All the threads already on here point to a problem where people accidentally create anonymous structs, such as

typedef struct{
    int a;
}; monkey

instead of

typedef struct monkey{
    int a;
}; monkey

So what am I missing????

There is no type called " struct LList ". The code " typedef struct linkedlist { ... } LList; " creates two type names: one is struct linkedlist , and the other is just LList (without " struct "). You thus need to change " struct LList " to " LList ."

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