开发者

"deferencing pointer to Incomplete type" error in c

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜