Even in some open source project, we always see memset filled in the code, here I had like give the reason why we should not use memset if possible.
memset was subject to give side-effect to your code.
memset description
In some projects, memset was used to flush the struct,
like the example given here bind example given in die.net
int main(int argc, char *argv[])
{
int sfd, cfd;
struct sockaddr_un my_addr, peer_addr;
...
memset(&my_addr, 0, sizeof(struct sockaddr_un));
/* Clear structure */
...
}
memset will flush with byte by byte in your raw memory. in such situations, only 0 or possible 0xFF was allowed, otherwise you will get some results more than what you expected.
Some examples like this one: good example
memset was not efficient than the other solution.
memset will have one function call when use it.
I will take this struct as example:

Disassemble code on the x86-64 arch machine.

how we handle this with more elegant manner? Use initlization!
struct sockaddr_un myaddr = {};
Have a look at the disassemble code:

Oops, it just use less code to finish this flush operation!
Don’t use memset anymore!