Query regarding syntax used in a header file for socket programming

前端 未结 3 1084
遥遥无期
遥遥无期 2021-01-20 13:32

This is the piece of the code I copied from one of the header file for socket programming.

/* Structure describing an Internet socket address.  */
struct soc         


        
3条回答
  •  情书的邮戳
    2021-01-20 13:49

    There exists the macro definition:

    #define __SOCKADDR_COMMON(sa_prefix) \
      sa_family_t sa_prefix##family
    

    so __SOCKADDR_COMMON (sin_); actually expands to sa_family_t sin_family;

    The way this happens is that the macro takes the parameter sa_prefix and uses the ## operator to concatenate (join) them. The result is that you have a new variable sin_family which is declared with type sa_family_t in the struct.

    Here's more info on macros and the C Preprocessor

提交回复
热议问题