Why use bzero over memset?
I don't see any reason to prefer bzero
over memset
.
memset
is a standard C function while bzero
has never been a C standard function. The rationale is probably because you can achieve exactly the same functionality using memset
function.
Now regarding efficiency, compilers like gcc
use builtin implementations for memset
which switch to a particular implementation when a constant 0
is detected. Same for glibc
when builtins are disabled.
I'm guessing you used (or your teacher was influenced by) UNIX Network Programming by W. Richard Stevens. He uses bzero
frequently instead of memset
, even in the most up-to-date edition. The book is so popular, I think it's become an idiom in network programming which is why you still see it used.
I would stick with memset
simply because bzero
is deprecated and reduces portability. I doubt you would see any real gains from using one over the other.