diff --git a/source/strings.tex b/source/strings.tex index a9615c7d91..f06fe285fe 100644 --- a/source/strings.tex +++ b/source/strings.tex @@ -5517,6 +5517,33 @@ immediately prior to copying the sequence of characters to the destination. Each of these functions returns a pointer to a suitable created object, if any, otherwise the value of the first parameter. +\begin{example} +\begin{codeblock} +int x = 0; +memmove(&x, &x, sizeof(int)); +assert(x == 0); // Passes. + +unsigned y; +memcpy(&y, &x, sizeof(int)); +assert(y == 0); // Passes. + +unsigned char bytes[4] = { + 0xff, 0xff, 0xff, 0xff +}; +memcpy(&y, bytes, 4); +assert(y == 0xffffffff); // Passes, assuming that \tcode{sizeof(unsigned)} equals \tcode{4}, + // and that \tcode{CHAR_BIT} equals \tcode{8}. +\end{codeblock} +Both \tcode{x} and \tcode{y} are transparently replaced\iref{basic.life} +with implicitly created objects in the storage of the old objects, +and refer to the new respective objects. +In the call to \tcode{memmove}, +the implicit object creation takes place after copying the bytes of \tcode{x} +into a temporary array, +and immediately before copying them into the implicitly created object. +Since \tcode{int} is trivially copyable\iref{basic.types.general}, +\tcode{x} retains the value \tcode{0}. +\end{example} \pnum \begin{note}