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 compilers in such cases?
Asked
Active
Viewed 1,301 times
2 Answers
10
Nothing to do with the compiler. Consider the following:
int x[100];
memmove(&x[1], &x[0], 99*sizeof(int));

Oliver Charlesworth
- 267,707
- 33
- 569
- 680
6
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.

Jerry Coffin
- 476,176
- 80
- 629
- 1,111