How do I handle byte order differences when reading/writing floating-point types in C?

后端 未结 6 1683
生来不讨喜
生来不讨喜 2020-12-03 11:56

I\'m devising a file format for my application, and I\'d obviously like for it to work on both big-endian and little-endian systems. I\'ve already found working solutions fo

6条回答
  •  清歌不尽
    2020-12-03 12:35

    XML is probably the most portable way to do it.

    However, it appears that you already have most of the parser built, but are stuck on the float/double issue. I would suggest writing it out as a string (to whatever precision you desire) and then reading that back in.

    Unless all your target platforms use IEEE-754 floats (and doubles), no byte-swapping tricks will work for you.

提交回复
热议问题