开发者

Is Endianness always an issue that needs to be considered?

开发者 https://www.devze.com 2023-03-10 02:28 出处:网络
Suppose we\'开发者_开发知识库re sending some data over the network ... it is my understanding that Endianness is unconditionally an issue as we don\'t know what receving machine expects and what sendi

Suppose we'开发者_开发知识库re sending some data over the network ... it is my understanding that Endianness is unconditionally an issue as we don't know what receving machine expects and what sending machine will send. As a rule of thumb is this correct?

Does the answer depend on the type of data is being sent, say, does it matter if we're sending a C-string vs, IEEE-style 4 byte float, for example?


Yes, endianness always needs to be considered and defined in a network protocol. It affects all types that are larger than a single byte. So a char based C-string will not be affected by it since it is just an array of single bytes, but a wchar_t based string needs to be converted if one of the machines is little endian and the other one big endian. The same applies to all larger types likes int and float etc..

0

精彩评论

暂无评论...
验证码 换一张
取 消