“的sizeof”的无效申请不完整的类型列表结构Ç [英] invalid application of 'sizeof' to incomplete type list struct C
本文介绍了“的sizeof”的无效申请不完整的类型列表结构Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现一个替换算法,与页面错误交易。所以我想用malloc来创造一个循环链表,并即时得到以下错误:无效申请的sizeof不完全类型
pageInMemory'.following是code:
I'm trying to implement an replacement algorithm that deals with page faults. So i'm trying to creat a circular linked list using malloc and im getting the following error: "invalid application of sizeof' to incomplete type
pageInMemory'.following is the code:
typedef struct {
int use;
int reference;
int free;
struct pageInMemory* next;
} pageInMemory;
int main()
{
int i;
struct pageInMemory* start, *nn, *temp, *hand;
start = NULL;
for(i=0; i< pNum; i++)
{
nn = (struct pageInMemory *)malloc(sizeof(struct pageInMemory));
nn->use = 0;
nn->free = 1;
if(start==NULL)
{
nn->next = nn;
start =nn;
}
else
{ // sfhsdifhsdifj sdijfjsd
temp = start;
while(temp->next != start)
{
temp = temp->next;
}
temp->next = nn;
nn->next = start;
start = nn;
}
}
hand = start;
temp = start;
while(temp->next != start->next)
{
printf("%d\n", temp->use); //hi
}
return 0;// bye
}
我也是不应该使用malloc这样?
so am i not supposed to use malloc this way ?
推荐答案
改变你的结构定义
struct pageInMemory{
int use;
int reference;
int free;
struct pageInMemory* next;
};
让你的code工作。
而就在您的信息不强制转换的void * malloc的距离来。
这篇关于“的sizeof”的无效申请不完整的类型列表结构Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文