我一直在試圖弄清楚今天大部分時間裏的指針,甚至在早些時候問過一個question,但現在我被困在別的東西上了。我有下面的代碼:在一個新的文件從不兼容的指針類型警告傳遞參數
typedef struct listnode *Node;
typedef struct listnode {
void *data;
Node next;
Node previous;
} Listnode;
typedef struct listhead *LIST;
typedef struct listhead {
int size;
Node first;
Node last;
Node current;
} Listhead;
#define MAXLISTS 50
static Listhead headpool[MAXLISTS];
static Listhead *headpoolp = headpool;
#define MAXNODES 1000
static Listnode nodepool[MAXNODES];
static Listnode *nodepoolp = nodepool;
LIST *ListCreate()
{
if(headpool + MAXLISTS - headpoolp >= 1)
{
headpoolp->size = 0;
headpoolp->first = NULL;
headpoolp->last = NULL;
headpoolp->current = NULL;
headpoolp++;
return &headpoolp-1; /* reference to old pointer */
}else
return NULL;
}
int ListCount(LIST list)
{
return list->size;
}
現在我有:
#include <stdio.h>
#include "the above file"
main()
{
/* Make a new LIST */
LIST *newlist;
newlist = ListCreate();
int i = ListCount(newlist);
printf("%d\n", i);
}
當我編譯,我得到以下警告(在printf
語句打印什麼應該):
file.c:9: warning: passing argument 1 of ‘ListCount’ from incompatible pointer type
我應該擔心這個警告嗎?代碼似乎做我想做的事情,但我顯然非常困惑於C中的指針。在瀏覽本網站上的問題後,我發現如果我向ListCount (void *) newlist
發送參數,我不會收到警告,我不明白爲什麼,也沒有什麼(void *)
真的...
任何幫助,將不勝感激,謝謝。
ListCount接受LIST?什麼是LIST?它在哪裏定義?你通過它LIST * – 2010-01-29 07:08:42
如果你沒有'typedef'指針類型,代碼將更容易被讀/調試。 – 2010-01-29 07:10:17
根據我的理解,LIST是一個指向名爲Listhead的結構體的指針。我對嗎? – hora 2010-01-29 07:11:55