标签:
#include <iostream> #include <string.h> using namespace std; void* memmove(void *dst, const void *src, size_t count){ // 容错处理 if (dst == NULL || src == NULL){ return NULL; } unsigned char *pdst = (unsigned char *)dst; const unsigned char *psrc = (const unsigned char *)src; //推断内存是否重叠 bool flag1 = (pdst >= psrc && pdst < psrc + count); bool flag2 = (psrc >= pdst && psrc < pdst + count); if (flag1 || flag2){ // 倒序拷贝 while (count){ *(pdst + count - 1) = *(psrc + count - 1); count--; }//while } else{ // 拷贝 while (count--){ *pdst = *psrc; pdst++; psrc++; }//while } return dst; }
版权声明:本文博主原创文章,博客,未经同意不得转载。
标签:
原文地址:http://www.cnblogs.com/bhlsheji/p/4906167.html