首页 > 其他 > 详细

memcpy 和 memmove

时间:2020-03-26 14:25:10      阅读:50      评论:0      收藏:0      [点我收藏+]

在发生overlap的情况下,memcpy在不同的平台是有差别的

这是例子

#include "stdio.h"

char str1[9] = "aabbccdd";

int main( void )
{
    printf("The string: %s\n", str1);
    memcpy(str1 + 2, str1, 6);
    printf("New string: %s\n", str1);

    strcpy(str1, "aabbccdd");   // reset string

    printf("The string: %s\n", str1);
    memmove(str1 + 2, str1, 6);
    printf("New string: %s\n", str1);
}

 在不同的Target上,memcpy的行为不同,memmove是一致的

所以memcpy的时候要注意这个问题

gcc on Ubuntu:
The string: aabbccdd
New string: aaaaaabb
The string: aabbccdd
New string: aaaabbcc

Some ARM Target
The string: aabbccdd
New string: aaaabbbb
The string: aabbccdd
New string: aaaabbcc

 

memcpy 和 memmove

原文:https://www.cnblogs.com/shinedream/p/12574010.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!