Preferred idiom for endianess-agnostic reads

后端 未结 3 1440
耶瑟儿~
耶瑟儿~ 2021-01-02 09:38

In the Plan 9 source code I often find code like this to read serialised data from a buffer with a well-defined endianess:

#include 

uint32_         


        
3条回答
  •  庸人自扰
    2021-01-02 10:06

    If you want to guaranty a conversions between a native platform order and a defined order (order on a network for example) you can let system libraries to the work and simply use the functions of : hton, htons, htonl and ntoh, ntohs, nthol.

    But I must admit that the include file is not guaranteed : under Windows I think it is winsock.h.

提交回复
热议问题