Hello everyone
I have been working on generic C data structure (Doubly Linked List) and I have a question:
------ List.c -----
struct node {
void *data;
struct node *next;
struct node *prev;
};
struct list {
unsigned int length;
struct node *head;
struct node *tail;
};
typedef struct list List;
// I also have functions ;-) and one of them is "init()" which initialize the list.
Now here is my problem, users can define a variable "List *list". Right now list is a BAD POINTER because it is not equal to (Point to) any memory address. Now I want to force users to call "init()" function first before calling any other functions in list.c
How can I do that?
"I thought about having global variable in list.c and make it as a flag "static int flag = 0" and if they call init() i change it to '1' but that does not work well ;-)"
Can someone point me to the right direction.
Thanks
Mark