开发者

"deferencing pointer to Incomplete type" error in c

开发者 https://www.devze.com 2023-04-06 09:56 出处:网络
I have two structures like this CODE EDITED: typedef struct { int threadId; void *stack; }gtthread_t; typedef struct

I have two structures like this

CODE EDITED:

typedef struct 
{
   int threadId;
   void *stack;
}gtthread_t;

typedef struct
{
   gtthread_t *th;
   struct list *next;
}list;

In my code, i have used the structures like:

list *temp;
gtthread_t thread;
if(temp->next->th->threadId != thread.threa开发者_如何学CdId && temp->next!=NULL) //error generated here
{
   //do something
}

The error is also occuring here:

free(temp->next->th->stack);

What am i doing wrong here? I have a node in temp->next (it is not NULL).

Any help will be appreciated


typedef struct
{
   gtthread_t *th;
   list *next;
}list;

When the parser is at line 3, it has no idea what list means. Try

typedef struct list
{
   gtthread_t *th;
   struct list *next;
}list;

instead.


Just rewrite the list like this;

struct list
{
   gtthread_t *th;
   struct list *next;
};
typedef struct list list;


This structure also needs to be created: temp->next->th->threadId

i.e.

temp = (list *)malloc(sizeof(list));
temp->next = (list *)malloc(sizeof(list));
temp->next->th = (gtthread_t *)malloc(sizeof(gtthread_t));
temp->next->th->threadId = <some value>
temp->next->th->stack = <some value>
0

精彩评论

暂无评论...
验证码 换一张
取 消