memcpy vs bcopy 
Author Message
 memcpy vs bcopy

Quote:

>I am using SUN-OS 4.1, and do not see major differences between
>memcpy and bcopy. The only one is that memcpy is likely not to
>behave in case of overlapping between arg1 and arg2.

Likewise for some implementations of bcopy().  It's never been entirely clear
whether it was supposed to implement memcpy() or memmove().

My recommendation: use memcpy() for non-overlapping moves, memmove() for
overlapping moves, and never use bcopy().

If you're porting a program that currently uses bcopy(), examine it to
determine whether the arguments could overlap or not; if you aren't sure, then
use memmove() to be safe, and ADD A COMMENT so your successor (or your future
self) will know that you weren't sure.

If you're using a backwards implementation that doesn't supply memcpy() and/or
memmove(), use them anyway -- and implement them yourself with a compatibility
library.  (But CONDITIONALLY.  Don't define them on systems where they already
exist!)  They are both short functions.  (You could even implement one or both
with calls to bcopy(), if that function exists and (for memmove) is known to
handle overlapping moves correctly, but I would normally just code the loop.)

Both memcpy() and memmove() are standard functions in ANSI C, and hence in
POSIX.  bcopy() has BSD and V7 ancestry, while memcpy() comes from the USG
line.  memmove() is a relatively recent addition; I believe it was proposed by
Rob Pike and may have appeared in V8.




Wed, 13 Apr 1994 01:38:10 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. memcpy != bcopy (Was Re: bcopy() bzero())

2. Q: memcpy(), strncpy() and bcopy()

3. Difference between bcopy and memcpy

4. bcopy or memcpy?

5. Script to replace bcopy() with memcpy()

6. Difference between memcpy() and bcopy()

7. memmove vs. memcpy

8. memcpy vs strcpy

9. strcpy vs. memcpy

10. strcpy() vs. memcpy()

11. Memcpy vs. assignment of structs

12. memcpy() vs for loop?

 

 
Powered by phpBB® Forum Software