Are IEEE float and double guaranteed to be the same size on any OS?

前端 未结 4 1059
北恋
北恋 2020-12-11 11:00

I\'m working on a OS portable database system. I want our database files to be OS portable so that customers can move their database files to other kinds of OS\'s at their d

4条回答
  •  醉梦人生
    2020-12-11 11:28

    --cut-- Nevermind https://stackoverflow.com/a/24157568/2422450 provides a better explanation for the float sizes.

    If you're however thinking about storing these floats in binary data files, do make sure you don't mess up the byte order or endianness. If you're dumping raw floats, some systems store the bytes in a different order, so casting the 4 bytes you just read to a double might give some surprising results.

提交回复
热议问题