开发者

No module definition file specified

So i have this code, the snippet is given below.

list* init(list* list1)
{
  list1->head = NULL;
  list1->size = 0;
  return list1;
}

list1 is a linked list and init is called from main function. now on the line list1->head= NULL, after i run the code it highlights this particular line and says

No module definition file specified: using defaults.

and it stopd execution.

I am using turbo C on windows 7.

what shal开发者_开发知识库l i do? Shall i post the complete code.. It is kinda big though..


Based on our discussion in the comments it looks like a combination of factors.

First, it appears the Turbo C compiler doesn't know what NULL is. Since NULL is just a typedef for 0, you can use 0 instead.

Second, it seems you haven't allocated memory for the list object. Try doing the following before you call the function.

list* list1 = malloc(sizeof(list));

However, if what you're trying to do is create and initialize a new list object, you're better off rewriting the function as follows:

list* init(){
    list *new_list = malloc(sizeof(list));
    new_list->head = 0; // <-- this sets head to the equivalent of NULL
    new_list->size =0;
    return new_list;
}

If what you want is a function that reinitializes an existing list, then you're causing a memory leak with your current code anyway.


NULL is defined in < stddef.h > for C, and the equivalent < cstddef > for C++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜