title: How to check Type of structure in C
body: <p>I made a simple listing struct in C that holds any kind of data using void* pointer, something like:</p>
  
  <pre><code>struct node
  {
      void *the_data;
      node *next;
  };
  </code></pre>
  
  <p>It is working just fine, but I have some lists that contains, for example, only struct_a in a list and only struct_b in another list. I need to check if the first element of the list is of struct_a type or struct_b type in a single if() question so I know the data that this list is holding. How to do this? Thanks</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I've come up with a simple solution that is enough for the problem now, dunno if it's the best:</p>
  
  <pre><code>struct node
  {
      void *data;
      node *next;
  }
  </code></pre>
  
  <p>And I added a "descriptor" node, which contains the address of the first node and info about the type:</p>
  
  <pre><code>struct list_desc
  {
      node *list;
      short int type;
  }
  </code></pre>
  
  <p>and I'll use it with some macros like</p>
  
  <pre><code>#define __data_type1 10
  #define __data_type2 20
  </code></pre>
  
  <p>so later I can compare like if( struct.type == __data_tipe1 ) etc...</p>