title: dynamic_cast and static_cast in C++
body: <p>I am quite confused with the <code>dynamic_cast</code> keyword in C++.</p>
  
  <pre><code>struct A {
      virtual void f() { }
  };
  struct B : public A { };
  struct C { };
  
  void f () {
      A a;
      B b;
  
      A* ap = &amp;b;
      B* b1 = dynamic_cast&lt;B*&gt; (&amp;a);  // NULL, because 'a' is not a 'B'
      B* b2 = dynamic_cast&lt;B*&gt; (ap);  // 'b'
      C* c = dynamic_cast&lt;C*&gt; (ap);   // NULL.
  
      A&amp; ar = dynamic_cast&lt;A&amp;&gt; (*ap); // Ok.
      B&amp; br = dynamic_cast&lt;B&amp;&gt; (*ap); // Ok.
      C&amp; cr = dynamic_cast&lt;C&amp;&gt; (*ap); // std::bad_cast
  }
  </code></pre>
  
  <p>the definition says:   </p>
  
  <blockquote>
    <p>The <code>dynamic_cast</code> keyword casts a datum from one pointer or reference 
        type to another, performing a runtime check to ensure the validity of the cast</p>
  </blockquote>
  
  <p>Can we write an equivalent of <code>dynamic_cast</code> of C++ in C so that I could better understand things?</p>