memcpy的实现

void *mymemcpy( void *dest, const void *src, size_t count )

{

    char *pdest = static_cast<char*>(dest);

    const char* psrc = static_cast<const char*>(src);

      

    if( pdest>psrc && pdest<psrc+count)//指针srcdest所指的内存区域重叠

    {

        for( size_t i=count-1; i!=-1; --i )

                     pdest[i] = psrc[i];

    }

    else

    {

        for( size_t i=0; i<count; ++i )

            pdest[i] = psrc[i];

    }

    return dest;

}

你可能感兴趣的:(C++)