Xref: utzoo comp.lang.c:12583 comp.std.c:371 Path: utzoo!utgpu!water!watmath!clyde!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c,comp.std.c Subject: Re: memcpy vs. memmove Message-ID: <7448@haddock.ima.isc.com> Date: 14 Sep 88 16:21:12 GMT References: <8389@smoke.ARPA> <7039@bloom-beacon.MIT.EDU> <2063@cuuxb.ATT.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Followup-To: comp.std.c Organization: Interactive Systems, Boston Lines: 19 In article <2063@cuuxb.ATT.COM> mmengel@cuuxb.ATT.COM (Marc Mengel) writes: >To check whether the source and destination overlap, you have to compare two >pointer values. You can only do this legally ($3.3.8) if the two pointers >point into the same array/aggregate. Watch it -- the first `you' refers to the implementation; the second refers to the user. Certainly the implementation is free to generate any code that happens to work. >Hence you need memmove() for shifting items in an array, and memcpy() for >moving items between arrays. Using memmove() on items not in the same array >is therefore not guaranteed to work, as the comparison of pointers not in the >same array/aggregate is undefined. No, memmove() is guaranteed to work on *any* valid pointers. What you've really proved is that memmove() cannot be portably implemented in C. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint Followups to comp.std.c.