没有合适的资源?快使用搜索试试~ 我知道了~
5.编程实现memcpy.docx
0 下载量 101 浏览量
2022-11-21
05:31:10
上传
评论
收藏 19KB DOCX 举报
温馨提示
试读
3页
5.编程实现memcpy.docx
资源推荐
资源详情
资源评论
1:函数原型 void * memcpy ( void * destination, const void * source,
size_t num );
函数作用
参考:http://www.cplusplus.com/reference/clibrary/cstring/memcpy/
Copy block of memory
Copies the values of num bytes from the location pointed by source directly to the
memory block pointed by destination.
The underlying type of the objects pointed by both the source and destination pointers
are irrelevant for this function; The result is a binary copy of the data.
The function does not check for any terminating null character in source - it always
copies exactly num bytes.
To avoid overflows, the size of the arrays pointed by both
the destination and source parameters, shall be at least numbytes, and should not
overlap (for overlapping memory blocks, memmove is a safer approach).
实现 1:《高质量 c++,c 编程指南》
[cpp] view plaincopyprint?
1. void *mymemcpy(void *dst,const void *src,size_t num)
2. {
3. assert((dst!=NULL)&&(src!=NULL));
4. //assert(des>=src+num||src>dst+num);
5. byte * psrc = (byte *)src;//byte 既为 unsigned char 类型
6. byte * pdst = (byte *)dst;
7. while(num-->0)*pdst++ = *psrc++;
8. return dst;
9. }
资源评论
Mmnnnbb123
- 粉丝: 679
- 资源: 8万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功