“s”是什么意思?结构中的意思?
这是一个简单的问题。 sin_family、sin_port、sin_addr 和 sin_zero 中的前导字母“s”有何含义?
struct sockaddr_in {
short int sin_family; // Address family, AF_INET
unsigned short int sin_port; // Port number
struct in_addr sin_addr; // Internet address
unsigned char sin_zero[8]; // Same size as struct sockaddr
};
谢谢。
Here's a simple question. What's the meaning of the leading letter "s" in the sin_family, sin_port, sin_addr and sin_zero?
struct sockaddr_in {
short int sin_family; // Address family, AF_INET
unsigned short int sin_port; // Port number
struct in_addr sin_addr; // Internet address
unsigned char sin_zero[8]; // Same size as struct sockaddr
};
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这来自伯克利,当时 LSD 还合法。他们的命名选择非常明显:/
开个玩笑,这可以追溯到非常早期的 K&RC,其中结构成员没有自己的命名空间。这要求您为结构成员提供不同的名称,这些名称不会与全局命名空间中的标识符发生冲突。痛苦。在名称前面加上结构名称的缩写是常见的方法。
因此“sockaddr_in”变成“sin”。
请注意,今天枚举仍然存在这个问题,并且通常以相同的方式解决。
This comes from Berkeley, back when LSD was still legal. So very obvious in their naming choices :/
All kidding aside, this dates back to very early K&R C where structure members didn't have their own namespace. Which required you to come up with distinct names for the structure members that wouldn't collide with identifiers in the global namespace. Painful. Prefixing the names with an abbreviation of the structure name was the common approach.
Thus "sockaddr_in" becomes "sin".
Note how enums still have this problem today, not untypically solved the same way.
sin
重复了sockaddr_in
结构的名称,即Socket INternet。sin
is repeating the name of thesockaddr_in
structure, i.e. Socket INternet.在本文中,“sin”代表“Socket Internet”。
"sin" stands for "Socket INternet" in this context.