title: Casting from void* to struct
body: <p>I am passing data of type struct Person to a linked list, so each node's data pointer points to a struct Person.</p>
  
  <pre><code>struct Person {
  char name[16];
  char text[24];
  };
  </code></pre>
  
  <p>I am trying to traverse the list and print the name/text in each node by calling</p>
  
  <pre><code>traverse(&amp;list, &amp;print);
  </code></pre>
  
  <p>Prototype for traverse is:</p>
  
  <pre><code>void traverseList(struct List *list, void (*f)(void *));   
  </code></pre>
  
  <p>List is defined as:</p>
  
  <pre><code>struct List {
  struct Node *head;
  };
  </code></pre>
  
  <p>My print function accepts a void * data :</p>
  
  <pre><code>print(void *data) { .... }
  </code></pre>
  
  <p>I know I have to cast the data to struct Person, correct?</p>
  
  <pre><code>struct Person *person = (struct Person *)data;
  printf("%s", person-&gt;name);
  </code></pre>
  
  <p>I know this is not sufficient since I am getting an "initialization from incompatible pointer type" warning. How can I successfully cast a void* in this case? Thank you.</p>