title: C two functions in one with casts
body: <p>I have two functions that do the exact same thing but in two different types of struct and this two types of struct are very similar.</p>
  
  <p>Imagine I have this two structs.</p>
  
  <pre><code>typedef struct nodeOne{
      Date *date;
      struct nodeOne *next;
      struct nodeOne *prev;
  }NodeOne;
  
  typedef struct nodeTwo{
      Date *date;
      struct nodeTwo *next;
      struct nodeTwo *prev;
  }NodeTwo;
  </code></pre>
  
  <p>Since my function to destroy each of the list is almost the same (Just the type of the arguments are different) I would like to make just one function to make the two thins.</p>
  
  <p>I have this two functions</p>
  
  <pre><code>void destroyListOne(NodeOne **head, NodeOne **tail){
      NodeOne *aux;
  
      while (*head != NULL){
          aux = *head;
          *head = (*head)-&gt;next;
          free(aux);
      }
      *tail = NULL;
  }
  </code></pre>
  
  <p>and this one:</p>
  
  <pre><code>void destroyListTwo(NodeTwo **head, NodeTwo **tail){
      NodeTwo *aux;
  
      while (*head != NULL){
          aux = *head;
          *head = (*head)-&gt;next;
          free(aux);
      }
      *tail = NULL;
  }
  </code></pre>
  
  <p>Since they are very similar I thought making something like this:</p>
  
  <pre><code>void destroyList(void **ini, void **end, int listType){
  
      if (listType == 0) {
          NodeOne *aux;
          NodeOne head = (NodeOne) ini;
          NodeOne tail = (NodeOne) ed;
  
      }
      else {
          NodeTwo *aux;
          NodeTwo head = (NodeTwo) ini;
          NodeTwo tail = (NodeTwo) ed;
      }
  
      while (*head != NULL){
          aux = *head;
          *head = (*head)-&gt;next;
          free(aux);
      }
      *tail = NULL;
  }
  </code></pre>
  
  <p>As you may now this is not working but I want to know if this is possible to achieve.</p>
  
  <p>I must maintain both of the structs as they are.</p>