void * memmove_kk(void * dest,const void *src,size_t count)
{
char *tmp, *s;
/*如果目标地址小于源地址的话,从头开始拷贝*/
if (dest <= src) {
tmp = (char *) dest;
s = (char *) src;
while (count--)
*tmp++ = *s++;
}
/*如果目标地址大于源地址的话,从尾部往前拷贝,这样就避免了当内存重叠时导致拷贝出错*/
else {
tmp = (char *) dest + count;
s = (char *) src + count;
while (count--)
*--tmp = *--s;
}
return dest;
}
阅读(1211) | 评论(0) | 转发(0) |