title: Safely casting struct pointers
body: <p>I had always thought that checking the pointer after casting a void* to a struct* was a valid way to avoid invalid casts. Something like</p>
  
  <pre><code>MyStructOne* pStructOne = (MyStructOne*)someVoidPointer;
  if(!pStructOne)
     return 0;
  </code></pre>
  
  <p>It appears that this is not the case as I can cast the same data to two different structs and get the same valid address. The program is then happy to populate my struct fields with whatever random data is in there.</p>
  
  <p><strong>What is a safe way of casting struct pointers?</strong></p>
  
  <p>I can't use dynamic_cast&lt;> as it's not a class.</p>
  
  <p>Thanks for the help!</p>