我仍然试图抓住C中的指针,结构和malloc。我试图用链表来实现哈希表。我碰到不兼容的指针类型的错误一回,当我尝试编译:从不兼容指针类型C返回
struct Mlist_head{
struct Mlist_node *head;
struct Mlist_node *tail;
};
struct MList {
int size;
struct Mlist_head hashtable[HASHSIZE];
};
MList *ml_create(void){
struct MList *m;
struct Mlist_head *h;
int i;
if ((m = (struct MList *)malloc(sizeof(struct MList))) != NULL){
if ((h = (struct Mlist_head *)malloc(sizeof(struct Mlist_head))) != NULL) {
for (i = 0; i < HASHSIZE; i++) {
h = &(m->hashtable[i]);
h->head = NULL;
h->tail = NULL;
}
printf("worked");
return m;
}
}
}
我敢肯定,有可能在同一时间:)
在这里(可能语义),但有一点其他错误感谢您的帮助
是的,“其他错误”之一是,如果分配失败,则根本不返回任何内容。 – 2011-05-02 17:17:00