title: memcpy a void pointer to a union
body: <p>Code: </p>
  
  <pre><code>union foo
  {
      char c;
      int i;
  };
  
  void func(void * src)
  {
      union foo dest;
      memcpy(&amp;dest, src, sizeof(union foo));   //here
  }
  </code></pre>
  
  <p>If I call <code>func()</code> like this:</p>
  
  <pre><code>int main()
  {
      char c;
      int i;
      func(&amp;c);
      func(&amp;i);
      return 0;
  }
  </code></pre>
  
  <p>In the call <code>func(&amp;c)</code>, the size of <code>c</code> is less than <code>sizeof(union foo)</code>, which may be dangerous, right?</p>
  
  <p>Is the line with <code>memcpy</code> correct?  And if not, how to fix it?</p>
  
  <p>What I want is a safe call to <code>memcpy</code> that copy a <code>void *</code> pointer to a <code>union</code>.</p>
  
  <hr>
  
  <p>A little background: this is extracted from a very complicated function, and the signature of <code>func()</code> including the <code>void *</code> parameter is out of my control. Of course the example does nothing useful, that's because I removed all the code that isn't relevant to provide an example with minimum code.</p>