Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.arch Subject: Re: Computer architects leaving Intel... Date: Wed, 11 Sep 2024 09:29:04 -0700 Organization: A noiseless patient Spider Lines: 26 Message-ID: <86frq6gnn3.fsf@linuxsc.com> References: <2024Aug30.161204@mips.complang.tuwien.ac.at> <86r09ulqyp.fsf@linuxsc.com> <2024Sep8.173639@mips.complang.tuwien.ac.at> <2024Sep10.101932@mips.complang.tuwien.ac.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Wed, 11 Sep 2024 18:29:05 +0200 (CEST) Injection-Info: dont-email.me; posting-host="6270473d9727e24675cb7c993eb45a62"; logging-data="3859491"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18oFG8yli3CM0XCeM/mPEeDOqcCvJ34PzA=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:yI/GSDc6NNuvey5idMuPqaP4rww= sha1:8evam7QMSgYYdyb7bXqD3rgmseI= Bytes: 1928 Josh Vanderhoof 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 _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; }