[comp.lang.c] memmove

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (06/17/90)

In article <1307@proto.COM> you (i.e. somebody, I lost the name) write:
>In article <16891@haddock.ima.isc.com>, karl@haddock.ima.isc.com (Karl Heuer) 
>writes:
>> #include <string.h>
>> void *memmove(void *adest, void *asrc, size_t n) {
>>     if (n != 0) {
>>         register char *dest = (char *)adest;
>>         register char *src = (char *)asrc;
>>         if (src > dest) {
>
               ^^^^^^^^^^
>The comparisions 'if(src > dest)' and 'if(src < dest)' will only compare
>the offset with most (all?) C compilers for the 80x86.  

They will compare segments if it is necessary: in huge model. 

Its worse than that: the indicated construct is not legal C. You don't
know that adest and asrc are in the same array or struct.
Its just plain illegal.

Memmove cannot be written in C. That is probably why it is included in
the library. In general it will require operating system calls.

Doug McDonald

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (06/17/90)

In article <1990Jun17.135623.754@ux1.cso.uiuc.edu> I write:
>
>Memmove cannot be written in C. 

My brain was dead. Of course it can. But you have to come up with 
a temporary array to store things in. People might get unhappy if
a vendor's memmove does TWO moves and a malloc.

I should have said "a direct memory to memory memmove cannot be
written in C".

Doug McDonald