简体   繁体   English

前缀在UNIX网络编程中是什么意思?

[英]What does the prefixes mean in UNIX NETWORK PROGRAMMING?

When I was reading the book Unix Network Programming , there are many socket apis/types having prefixes like sin_addr with sin , inet_addr with inet , and in_addr_t with in . 当我在读这本书的Unix网络编程 ,有很多Socket API的应用/有比如前缀类型sin_addrsininet_addrinet ,并in_addr_tin What do those prefiexes actually mean, that is, what are the full names? 这些首选项实际上是什么意思,即全名是什么?

I believe in the very early days structure members had to be unique. 我相信,在早期,结构成员必须是唯一的。 Using the same name for a member in two different structures failed. 在两个不同结构中为成员使用相同的名称失败。 This is still (and always was) true for assembly macros that help use C structs and preprocessor macros. 对于有助于使用C结构和预处理器宏的程序集宏来说,这仍然是(而且一直是)。

The structures and constants from the old days therefor use a prefix that is usually derived from the structure name or context. 因此,过去的结构和常量使用的前缀通常是从结构名称或上下文派生的。 Eg struct addressinfo uses a prefix of ai, struct sockaddr uses sa, struct sockaddr_in uses sin and so on. 例如,struct addressinfo使用ai前缀,struct sockaddr使用sa,struct sockaddr_in使用sin等。

Using unique names for each member allows using the same name for C and asm code, which made reading and writing code in both languages easier. 为每个成员使用唯一的名称允许对C和asm代码使用相同的名称,这使得在两种语言中读取和编写代码更加容易。 No need to mentally switch tracks when switching language. 切换语言时,无需在思维上切换音轨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM