The code is still wrong for another reason: if (uintptr_t)ptrOld &lt; (uintptr_t)ptrNew, then the subtraction is calculated modulo some power of 2 yielding a large number. The result of converting this to a signed integral type like ptrdiff_t is implementation defined.<p>In practice it works only if sizeof(ptrdiff_t) == sizeof(uintptr_t) AND the system uses two&#x27;s complement for signed integers. Neither property is guaranteed by the standard.<p>I think the correct way to find the byte offset is this:<p><pre><code>  ptrdiff_t diff = (char*)ptrOld - (char*)ptrNew;</code></pre>