title: In C, does a pointer to a structure always point to its first member?
body: <p>Suppose I have a number of C structs for which I would like a particular set of functions to operate upon. </p>
  
  <p>I'm wondering if the following is a legitimate approach: </p>
  
  <pre><code>typedef struct Base {
       int exampleMember;
       // ...
  } Base;
  
  typedef struct Foo {
       Base base;
       // ...
  } Foo;
  
  typedef struct Bar {
       Base base;
       // ...
  } Bar;
  
  void MethodOperatesOnBase(void *);
  
  void MethodOperatesOnBase(void * obj)
  {
       Base * base = obj;
       base-&gt;exampleMember++;
  }
  </code></pre>
  
  <p>In the example you'll notice that both structs <code>Foo</code> and <code>Bar</code> begin with a <code>Base</code> member.</p>
  
  <p>And, that in <code>MethodOperatesOnBase</code>, I cast the <code>void *</code> parameter to <code>Base *</code>.</p>
  
  <p>I'd like to pass pointers to <code>Bar</code> and pointers to <code>Foo</code> to this method and rely on the first member of the struct to be a <code>Base</code> struct.</p>
  
  <p>Is this acceptable, or are there some (possibly compiler-specific) issues I need to be aware of? (Such as some sort of packing/padding scheme that would change the location of the first  member of a struct?)</p>