title: Casting a void pointer to an arbitrary type pointer
body: <p>I am attempting to do my own implementation of common data structures in C for my own learning benefit.  My current effort is a vector, and I want it to be able to hold a single arbitrary type (or at least type size, but isn't that all that really matters in C?).  My struct is as follows:</p>
  
  <pre><code>struct vector
  {
      void *item;
      size_t element_size;
      size_t num_elements;
  }
  </code></pre>
  
  <p>However, what I don't understand is how I can refer to specific elements in the *item array if the type is supposed to be arbitrary.  I know the element_size, but that doesn't help me with index referencing (e.g. item[5]) because void is not a type.  I figured it would be easiest to refer to the elements as byte offsets.  So if I was holding a vector of structs with size 12, item[5] would be at 12*5=60 bytes from item*.  However, I don't understand how to retrieve that data.  I know I want 12 bytes from item+60, but how would I make the compiler understand that?  Am I getting into preprocessor territory?</p>