I tried to define pointers to C today, even asked a question earlier, but now I'm stuck on something else. I have the following code:
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; }else return NULL; } int ListCount(LIST list) { return list->size; }
Now in the new file I have:
#include <stdio.h> #include "the above file" main() { /* Make a new LIST */ LIST *newlist; newlist = ListCreate(); int i = ListCount(newlist); printf("%d\n", i); }
When compiling, I get the following warning (the printf statement prints what it should):
file.c:9: warning: passing argument 1 of 'ListCount' from incompatible pointer type
Should I worry about this warning? It seems that the code does what I want, but I obviously got very confused about the pointers to C. After looking at the questions on this site, I found that if I make the ListCount (void *) newlist , I won't get a warning, and I donβt understand why, and what (void *) really does ...
Any help would be appreciated, thanks.
source share