struct  hostent
{
  char    *h_name;        /* official name of host */
  char    **h_aliases;    /* alias list */
  int     h_addrtype;     /* host address type */
  int     h_length;       /* length of address */
  char    **h_addr_list;  /* list of addresses from name server */
  #define h_addr  h_addr_list[0]  /* address, for backward compatiblity */
};

例如以上结构体:

定义一个变量: struct hostent he;


此deinfe的宏和结构体本身没有任何关系,同定义在结构体外面没任何区别。
但是这样做是使的以前的旧的代码he.h_addr不需要做修改,则可以实现he.h_addr_list[0]的改变。


我猜测放到里面的作用主要是便于代码的查阅,此宏的主要作用是用于此结构体而已。


参阅资料:http://stackoverflow.com/questions/12247255/defining-macro-inside-of-struct-definition


 

相关文章:

  • 2021-10-11
  • 2021-10-17
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-08-11
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2021-12-02
  • 2022-02-12
  • 2022-12-23
相关资源
相似解决方案