Please look into this inexplicable behavior and output of memcpy() for overlapping memory blocks

有些话、适合烂在心里 提交于 2019-11-29 18:52:06

If the objects overlap, the behaviour of memcpy is undefined. There's little point in trying to reason about undefined behaviour. Since it is undefined it defies reason. You know the rules, and they are clearly documented. If the objects overlap, use memmove.

As for the use of "as if", that is to specify behaviour but not place any limitations on implementation. This allows the library implementor to use whatever method they see fit, so long as the end result is the same as using an intermediate buffer. For example, the implementation could detect that the objects do not overlap and so avoid using an intermediate buffer for performance reasons.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!