Sujet : Re: Computer architects leaving Intel...
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.archDate : 11. Sep 2024, 17:29:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86frq6gnn3.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Josh Vanderhoof <
x@y.z> writes:
[how to write a portable, UB-free check if mempcy() intervals overlap]
It is legal to test for equality between pointers to different objects
Right. This observation is the key insight.
so you could test for overlap by testing against every element in the
array.
For a complete test, compare the address of every element in both
arrays. For example:
#include <stddef.h>
_Bool
memcpy_intervals_overlap( void *const vd, void *const vs, size_t n ){
char *d = vd, *s = vs;
size_t k = 0;
while( k < n && d != vs && s != vd ) k++, d++, s++;
return k < n;
}