I understand the difference between memcpy
and memmove
: memmove
handles the overlapping of src
and dst
. I checked the man page for bcopy
and it seems to also handle overlapping. So I'm wondering if there is any difference between memmove
and bcopy
?
bcopy
and memmove
do exactly the same thing. However, they take arguments in a different order: bcopy(src, dest, n)
vs memmove(dest, src, n)
. So they can't be two names for the same function.
Historically, bcopy
is the older of the two; it was present in 3BSD if memory serves. memmove
was invented by the C committee in 1988 or so.
New code should use memmove
, as it is required by the C standard and therefore more portable than bcopy
.
The main difference normally comes from their origin. bcopy
comes from Berkeley Source Distribution (BSD) systems, while memcpy
and their family come mainly from AT&T's System V. And finally, by complying with legacy code, all those functions were included in the standards.
There's a good explanation about the use of memset
vs bzero
in Richard Steven's book "UNIX network programming" that somewhat explains about the use of either one.
Today implementations just resolve to calling the same internal implementation but providing both interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With