旅途

如果想飞得高,就该把地平线忘掉

memmove

贴个VC下的源码看看:
void * __cdecl memmove ( void * dst, const void * src, size_t count  )
{
        void * ret = dst;

        if (dst <= src || (char *)dst >= ((char *)src + count)) {
                /*
                 * Non-Overlapping Buffers
                 * copy from lower addresses to higher addresses
                 */
                while (count--) {
                        *(char *)dst = *(char *)src;
                        dst = (char *)dst + 1;
                        src = (char *)src + 1;
                }
        }
        else {
                /*
                 * Overlapping Buffers
                 * copy from higher addresses to lower addresses
                 */
                dst = (char *)dst + count - 1;
                src = (char *)src + count - 1;

                while (count--) {
                        *(char *)dst = *(char *)src;
                        dst = (char *)dst - 1;
                        src = (char *)src - 1;
                }
        }

        return(ret);
}

void * memmove(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;
 }

posted on 2007-10-22 00:37 旅途 阅读(194) 评论(0)  编辑 收藏 引用 所属分类: C/C++


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理