Why does an 8-bit field have endianness?

后端 未结 6 2118
天命终不由人
天命终不由人 2021-02-07 10:58

See the definition of TCP header in /netinet/tcp.h:

struct tcphdr
  {
    u_int16_t th_sport;         /* source port */
    u_int16_t th_dport;         /* destin         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 11:12

    My reading of the comment is that the two one-byte fields together are construed as a two-byte value (or were -- seems like one byte is unused anyway). Rather than declare one two-byte value, they declare two one-byte values but reverse the order of declaration depending on endian-ness.

提交回复
热议问题