When zeroing a struct such as sockaddr_in, sockaddr_in6 and addrinfo before use, which is correct: memset, an initializer or either?

后端 未结 5 1692
执笔经年
执笔经年 2020-12-14 17:36

Whenever I look at real code or example socket code in books, man pages and websites, I almost always see something like:

struct sockaddr_in foo;
memset(&         


        
5条回答
  •  北海茫月
    2020-12-14 17:42

    Either one is correct as many have pointed out. Additionally you can allocate these structures with calloc which already returns a zeroed memory block.

提交回复
热议问题