In a Systems Programming class I took this previous semester, we had to implement a basic client/server in C. When initializing the structs, like
sock_addr_in, or char buffers (that we used to send data back and forth between client and server) the professor instructed us to only use
bzero and not
memset to initialize them. He never explained why, and I’m curious if there is a valid reason for this?
I see here: http://fdiv.net/2009/01/14/memset-vs-bzero-ultimate-showdown that
bzero is more efficient due to the fact that is only ever going to be zeroing memory, so it doesn’t have to do any additional checking that
memset may do. That still doesn’t necessarily seem like a reason to absolutely not use
memset for zeroing memory though.
bzero is considered deprecated, and furthermore is a not a standard C function. According to the manual,
memset is preferred over
bzero for this reason. So why would you want to still use
memset? Just for the efficiency gains, or is it something more? Likewise, what are the benefits of
bzero that make it the de facto preferred option for newer programs?