Iosif Murariu Iosif Murariu - 1 year ago 150
Linux Question

bzero() & bcopy() versus memset() & memcpy()

Is there any reason to use the non-standard

instead of
in a Linux environment? I've heard many say that they're better for Linux compilers, but haven't seen any advantages over the standard functions.

Are they more optimized than the standard ones, or do they have any behavioral particularity for which they're preferred?

Answer Source

Well, bzero and bcopy aren't actually standard C, they were a POSIX thing (in terms of official standards - in actuality they predated both ISO and POSIX).

And note that word "were" - they were deprecated in POSIX.1-2001 and removed in POSIX.1-2008 in deference to memset and memcpy so you're better off using the standard C functions.

Edit: for those who need a quick substitution:

// void bzero(void *s, size_t n);
#define bzero(s, n) memset((s), 0, (n))
// void bcopy(const void *s1, void *s2, size_t n);
#define bcopy(s1, s2, n) memcpy((s2), (s1), (n))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download