Is endian conversion required for wchar_t data?

后端 未结 3 1439
清歌不尽
清歌不尽 2020-12-18 02:24

In C/C++, if a multi-byte wide character (wchar_t) value is transmitted from a big-endian system to a little-endian system (or vice-versa), will it come out the same value o

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-18 03:24

    Yes, you need to perform endian conversion. Define carefully your serialization format, i.e. the byte order of data that is transmitted over the network or stored into a disk file. Then, when sending data, convert from native to wire format (may or may not require byte swapping), and when receiving data, convert from wire to native format (again may or may not require byte swapping). You should pick a wire format that will be used by the majority of clients to minimize the average amount of byte swapping.

提交回复
热议问题