I am trying to create a Linkedlist using C, and I keep getting this error when I try to compile it,
warning: assignment to ‘struct ListNode *’ from incompatible pointer type ‘ListNode *’ [-Wincompatible-pointer-types]
These are my structs:
typedef struct {
void *data;
struct ListNode *next;
struct ListNode *prev;
} ListNode;
typedef struct {
ListNode *head;
ListNode *tail;
int size;
} LinkedList;
the whole list of warnings is shown down below:
linkedList.c:26:21: warning: assignment to ‘struct ListNode *’ from incompatible pointer type ‘ListNode *’ [-Wincompatible-pointer-types]
26 | newNd->next = list->head;
| ^
linkedList.c: In function ‘printList’:
linkedList.c:47:16: warning: assignment to ‘ListNode *’ from incompatible pointer type ‘struct ListNode *’ [-Wincompatible-pointer-types]
47 | currNd = currNd->next;
| ^
linkedList.c: In function ‘removeStart’:
linkedList.c:59:16: warning: assignment to ‘ListNode *’ from incompatible pointer type ‘struct ListNode *’ [-Wincompatible-pointer-types]
59 | list->head = temp->next;
| ^
linkedList.c: In function ‘insertLast’:
linkedList.c:88:18: warning: assignment to ‘ListNode *’ from incompatible pointer type ‘struct ListNode *’ [-Wincompatible-pointer-types]
88 | temp = temp->next;
| ^
linkedList.c:90:20: warning: assignment to ‘struct ListNode *’ from incompatible pointer type ‘ListNode *’ [-Wincompatible-pointer-types]
90 | temp->next = newNd;
| ^
linkedList.c: In function ‘removeLast’:
linkedList.c:109:14: warning: assignment to ‘ListNode *’ from incompatible pointer type ‘struct ListNode *’ [-Wincompatible-pointer-types]
109 | curr = curr->next;
| ^
If any more information is required, I am happy to add more.
You created a typedef of an anonymous struct when you defined
ListNode. It is therefore not the same asstruct ListNode. What you need to do is