我正在尝试实现一种处理页面错误的替换算法。所以我正在尝试使用 malloc 创建一个循环链表,我收到以下错误:“ sizeof' to incomplete type
pageInMemory 的无效应用程序”。以下是代码:
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 吗?