Using memcpy
to copy between overlapping memory regions. For example:
char a[256] = {};
memcpy(a, a, sizeof(a));
The behavior is undefined according to the C Standard, which is subsumed by the C++03 Standard.
7.21.2.1 The memcpy function
Synopsis
1/ #include void *memcpy(void * restrict s1, const
void * restrict s2, size_t n);
Description
2/ The memcpy function
copies n characters from the object pointed to by s2 into the object
pointed to by s1. If copying takes place between objects that overlap,
the behavior is undefined. Returns 3 The memcpy function returns the
value of s1.
7.21.2.2 The memmove function
Synopsis
1 #include void *memmove(void *s1, const void *s2, size_t
n);
Description
2 The memmove function copies n characters from the object pointed to
by s2 into the object pointed to by s1. Copying takes place as if the
n characters from the object pointed to by s2 are first copied into a
temporary array of n characters that does not overlap the objects
pointed to by s1 and s2, and then the n characters from the temporary
array are copied into the object pointed to by s1. Returns
3 The memmove function returns the value of s1.