title: Down Casting a Hierarchy with Nonpolymorphic Types
body: <p><strong>This is strictly in C.</strong></p>
  
  <p>Say you're given one base struct, and 2 other derived structs. These derived structs are not derived in the classical sense (ie: A : B), rather, they only contain structs of the base type. So if struct A is the base and B is one of the 2 derived structs, B would have a member of type A. Like this:</p>
  
  <pre><code>struct A {
       // blah blah...
  };
  
  struct B {
       A part_a;
       // more stuff...
  }
  
  struct C {
       A part_a;
       // SO MUCH STUFF
  }
  </code></pre>
  
  <p>Say you have a function, A_downcast_B, something like this:</p>
  
  <pre><code>B * A_downcast_B(A * a)
  {
       // downcast the A* here somehow
  }
  </code></pre>
  
  <p>You want this function to return <code>0</code> or <code>-1</code> if <code>'a'</code> could not be successfully downcasted to a struct of type <code>B</code>. So for example, if a 'derived' struct of type <code>C</code> had a pointer to it of type <code>A*</code>, and that pointer were passed to this function, the function would return <code>0</code>, <code>-1</code> or <code>null</code>.</p>
  
  <p>Is there a way to do this? I've been thinking about this for a few hours now and it's got me stumped.</p>