title: Is it possible to cast pointers from a structure type to another structure type extending the first in C?
body: <p>If I have structure definitions, for example, like these:</p>
  <pre><code>struct Base {
    int foo;
  };
  
  struct Derived {
    int foo; // int foo is common for both definitions
    char *bar;
  };
  </code></pre>
  <p>Can I do something like this?</p>
  <pre><code>void foobar(void *ptr) {
    ((struct Base *)ptr)-&gt;foo = 1;
  }
  
  struct Derived s;
  
  foobar(&amp;s);
  </code></pre>
  <p>In other words, can I cast the void pointer to <code>Base *</code> to access its <code>foo</code> member when its type is actually <code>Derived *</code>?</p>