我試圖實現一個處理頁面錯誤的替換算法。所以我想用malloc來創造一個循環鏈表,並即時得到以下錯誤:「sizeof' to incomplete type
pageInMemory'.following的無效申請代碼:將'sizeof'應用於不完整類型列表struct C
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這樣?
當你做一個typedef時,我向你推薦這個語法:typedef struct foo {...} foo;這更清楚。 – Shar