title: memcpy of overlapping buffers
body: <p>I ran into strange behavior when using the Aztec linear system solver library. Using valgrind, I found out that this library does a <code>memcpy</code> on overlapping buffers. Specification says that behavior of <code>memcpy</code> on overlapping buffers is not defined.</p>
  
  <p>It turns out that <code>memcpy</code> on many machines has the same behavior as if you would do it with a  for loop and therefore you can safely copy from a higher source to a lower destination:</p>
  
  <pre><code>for(int i = 0; i &lt; len; i ++)
    dest[i] = source[i];
  </code></pre>
  
  <p>BUT on our large cluster, <code>memcpy</code> of overlapping buffers has a different behavior which leads to problems.</p>
  
  <p>Now I wonder whether the overlapping <code>memcpy</code> in the library is normal or just caused by another bug in my code. Since the library is widely used I assume that the <code>memcpy</code> issue should have been discovered earlier. On the other hand, it's still possible that the vast majority of the <code>memcpy</code> implementations behave like the for loop and therefore nobody ever encountered this problem.</p>
  
  <ul>
  <li>Can anyone tell me about his experiences with overlapping <code>memcpy</code> on various machines?</li>
  <li>Which part of my computer system does actually provide <code>memcpy</code>?</li>
  </ul>
  
  <p>I'd like to point out that question is about the practical experience with various implementations, not about what the specification says.</p>