title: Does dynamic type choice break strict aliasing in C?
body: <p>Let's say that I have some code that looks like this:</p>
  
  <pre><code>void foo(void* obj, int type)
  {
      TypeA* a = (TypeA*)obj;
      TypeB* b = (TypeB*)obj;
      TypeC* c = (TypeC*)obj;
  
      if( type == 1 ) {
          // code that uses "a"
      }
      else if( type == 2 ) {
          // code that uses "b"
      }
      else if( type == 3 ) {
          // code that uses "c"
      }
  }
  </code></pre>
  
  <p>I'm curious to know whether or not this function breaks strict aliasing a
  priori, or if the validity of the function depends on how it's actually used.
  A certain part of me wants to hope that things will work out fine if I only
  ever used the function as <code>foo(&amp;objectOfTypeA, 1)</code>, <code>foo(&amp;objectOfTypeB, 2)</code>,
  or <code>foo(&amp;objectOfTypeC, 3)</code>. Yet I've only know about aliasing errors for a
  few days, and so I worry that the function <code>foo()</code> is broken right from the
  start simply because it casts the incoming void* to various different types to
  begin with.</p>