“引用指向不完整类型的指针” c中的错误

发布于 2024-12-05 21:09:04 字数 571 浏览 3 评论 0原文

我有两个这样的结构

代码编辑:

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

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

在我的代码中,我使用了如下结构:

list *temp;
gtthread_t thread;
if(temp->next->th->threadId != thread.threadId && temp->next!=NULL) //error generated here
{
   //do something
}

错误也发生在这里:

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

我在这里做错了什么?我在 temp->next 中有一个节点(它不是 NULL)。

任何帮助将不胜感激

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.threadId && 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灼疼热情 2024-12-12 21:09:04
typedef struct
{
   gtthread_t *th;
   list *next;
}list;

当解析器位于第 3 行时,它不知道 list 的含义。尝试

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

一下。

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.

滥情稳全场 2024-12-12 21:09:04

只需像这样重写列表即可;

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

Just rewrite the list like this;

struct list
{
   gtthread_t *th;
   struct list *next;
};
typedef struct list list;
撧情箌佬 2024-12-12 21:09:04

还需要创建这个结构体:temp->next->th->threadId

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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文