title: Passing a void pointer to a function pointer
body: <p>In brief, I am attempting to use a void pointer as a parameter to a function pointer, but am getting the compiler error "invalid use of void expression".</p>
  
  <p>I have a doubly linked list (DLL) whose node structure is as follows:</p>
  
  <pre><code>typedef struct DL_LIST
  {
      uint16 tag;                 /* Object ID tag */
      struct DL_LIST *previous;
      struct DL_LIST *next;
      void *object;               /* A pointer to this node's object */
      uint32 size;                /* The size of this node's object, in bytes */
  } DL_LIST;
  </code></pre>
  
  <p>I also have the following function which is used to delete a single such node:</p>
  
  <pre><code>void dl_delete(DL_LIST *node, void (*dl_destructor)(void*)) {
      if (node != NULL) {
          dl_extract(node);       /* Removes the node from the list */
  
          if (node-&gt;object != NULL) {
              (*dl_destructor)(node-&gt;object);
  
              free(node-&gt;object);
          }
  
          free(node);
      }
  }
  </code></pre>
  
  <p>where the node extraction function is:</p>
  
  <pre><code>DL_LIST *dl_extract(DL_LIST *node) {
      if (node != NULL) {
          if (node-&gt;previous != NULL) {
              node-&gt;previous-&gt;next = node-&gt;next;
          }
  
          if (node-&gt;next != NULL) {
              node-&gt;next-&gt;previous = node-&gt;previous;
          }
  
          node-&gt;previous = NULL;
          node-&gt;next = NULL;
      }
  
      return node;
  }
  </code></pre>
  
  <p>The idea here is to be able to pass a separate destructor function for each type of <code>object</code> that may be stored in a node. This destructor function takes a pointer to the object as a parameter, and is used to free any heap memory that is being used by children of the <code>object</code>.</p>
  
  <p>The aforementioned error occurs when I try to call <code>dl_delete()</code> from a function designed to delete an entire DLL:</p>
  
  <pre><code>void dl_destroy(DL_LIST **list, void (*dl_destructor)(void*)) {
      DL_LIST *marker;
      DL_LIST *previous_node;
  
      if (*list != NULL) {
          previous_node = (*list)-&gt;previous;
  
          while (previous_node != NULL) {
              marker = previous_node-&gt;previous;
              dl_delete(previous_node, (*dl_destructor)(previous_node-&gt;object));
              previous_node = marker;
          }
  
          /* Code removed for brevity */
      }
  }
  </code></pre>
  
  <p>I have read <a href="https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work">this</a> introduction to function pointers, but am still unable to determine how to remedy the problem. An explanation of what I am doing wrong would be most appreciated.</p>