title: Linked list error
body: <p>I have an error and a warning while trying to compile my linked list implementation in c</p>
  
  <blockquote>
    <p>warning: assignment from incompatible pointer type</p>
    
    <p>error: dereferencing pointer to incomplete type
    here is the list.h</p>
  </blockquote>
  
  <pre><code>#ifndef LIST_H
  #define LIST_H
  #include &lt;stdio.h&gt;
  
  typedef struct _ListElmt{
  
  void                *data;
  struct ListElmt     *next;
  
  } ListElmt;
  typedef struct _List{
  
  int                 size;
  int                 (*match)(const void *key1, const void *key2);
  void                (*destroy)(void *data);
  
  ListElmt             *head;
  ListElmt             *tail;
  
  } List;
  
  void list_init(List *list, void (*destroy)(void *data));
  
  void list_destroy(List *list);
  
  int list_ins_next(List *list, ListElmt *element, const void *data);
  
  int list_rem_next(List *list, ListElmt *element, void **data);
  
  int list_size(const List *list);
  
  ListElmt *list_head(const List *list);
  
  ListElmt *list_tail(const List *list);
  
  int list_is_head(const ListElmt *element);
  
  int list_is_tail(const ListElmt *element);
  
  void *list_data(const ListElmt *element);
  
  ListElmt *list_next(const ListElmt *element);
  #endif
  </code></pre>
  
  <p>and here is the list.c</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include "List.h"
  
  void list_init(List *list, void (*destroy)(void *data)){
  
  list-&gt;size = 0;
  list-&gt;destroy = destroy;
  list-&gt;head = NULL;
  list-&gt;tail  = NULL;
  
  return;
  }
  
  void list_destroy(List *list){
  
  void                *data;
  
  while(list_size(list) &gt; 0){
  
      if(list_rem_next(list, NULL, (void **)&amp;data) == 0 &amp;&amp; list-&gt;destroy != NULL){
  
          list-&gt;destroy(data);
      }
  }
  memset(list, 0, sizeof(List));
  return;
  }
  
  int list_ins_next(List *list, ListElmt *element, const void *data){
  
  ListElmt            *new_element;
  
  if((new_element = (ListElmt *)malloc(sizeof(ListElmt))) == NULL) // not yet understanded
      return -1;
  
  new_element-&gt;data = (void *)data;
  
  if(element == NULL){
      if(list_size(list) == 0)
          list-&gt;tail = new_element;
  
      new_element-&gt;next = list-&gt;head;
      list-&gt;head = new_element;
  }
  
  else{
      if(element-&gt;next == NULL)
          list-&gt;tail = new_element;
  
      new_element-&gt;next = element-&gt;next;
      element-&gt;next = new_element;
  }
  
  list-&gt;size++;
  return 0;
  }
  
  int list_rem_next(List *list, ListElmt *element, void **data){
  
  ListElmt            *old_element;
  
  if(list_size(list) == 0)
      return -1;
  
  if(element == NULL){ // Handle removal of the head
  
          *data = list-&gt;head-&gt;data;
          old_element = list-&gt;head;
          list-&gt;head = list-&gt;head-&gt;next;
  
          if(list_size(list) == 1)
              list-&gt;tail = NULL;
  }
  
  else{ // Handle removal from somewhere else
  
      if(element-&gt;next == NULL)
          return -1;
  
      *data = element-&gt;next-&gt;data;
      old_element = element-&gt;next;
      element-&gt;next = element-&gt;next-&gt;next;
  
     if (element-&gt;next == NULL)
        list-&gt;tail = element;
  }
  
  free(old_element);
  
  list-&gt;size--;
  return 0;
  }
  </code></pre>