Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions source/strings.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down