开发者

memmove implementation

In reference to the thread: memmove implementation in C, I did not understand why would there be a memory overlap for 2 different variables? i.e. is this a normal scenario that the compiler allocates same 'common space' to 2 different variables and why is this policy used by 开发者_如何学JAVAcompilers in such cases?


Nothing to do with the compiler. Consider the following:

int x[100];

memmove(&x[1], &x[0], 99*sizeof(int));


It's not really about the compiler creating variables that overlap. It's simply that the specification of memmove says it has to work, even if the source and destination overlap. If there's no chance of the two overlapping, you usually want to use memcpy, which will usually be faster, but gives undefined behavior if they do overlap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜