Is there a way to enforce specific endianness for a C or C++ struct?

前端 未结 11 1224
南方客
南方客 2020-12-13 09:24

I\'ve seen a few questions and answers regarding to the endianness of structs, but they were about detecting the endianness of a system, or converting data between the two d

11条回答
  •  北海茫月
    2020-12-13 10:01

    There is a data representation for this called XDR. Have a look at it. http://en.wikipedia.org/wiki/External_Data_Representation

    Though it might be a little too much for your Embedded System. Try searching for an already implemented library that you can use (check license restrictions!).

    XDR is generally used in Network systems, since they need a way to move data in an Endianness independent way. Though nothing says that it cannot be used outside of networks.

提交回复
热议问题