title: Is it technically impossible to implement memcpy from scratch in Standard C?
body: <p>Howard Chu <a href="https://twitter.com/hyc_symas/status/1088187814477553678" rel="nofollow noreferrer">writes</a>: </p>
  
  <blockquote>
    <p>In the latest C spec it is impossible to write a "legal" implementation of malloc or memcpy.</p>
  </blockquote>
  
  <p>Is this right? My impression is that in the past, the intent (at least) of the standard was that something like this would work:</p>
  
  <pre class="lang-c prettyprint-override"><code>void * memcpy(void * restrict destination, const void * restrict source, size_t nbytes)
  {
      size_t i;
      unsigned char *dst = (unsigned char *) destination;
      const unsigned char *src = (const unsigned char *) source;
  
      for (i = 0; i &lt; nbytes; i++)
          dst[i] = src[i];
      return destination;
  }
  </code></pre>
  
  <p>What rules in the latest C standard are violated here? Or, what part of the specification of <code>memcpy</code> is not correctly implemented by this code?</p>