0

Short question. If I set first byte in binary file as a flag to check if it is created on little endian hardware, would I do good? First byte could be one byte value 0 or 1 which is possible to cast to bool later.

Akasata Akasata
  • 333
  • 4
  • 10
  • 1
    Yes. You still need to fix each read after that with your own code but that byte would let you know which endian is up. – Dave S Jul 02 '18 at 20:40
  • Since you are making your own file format, you also can just say "the file will always be in (little endian) or always be in (big endian) format. Then you only need to fix files on machines using the other endian: those machines fix the file both on write and on read. – Dave S Jul 02 '18 at 20:45
  • That's what I wanted to do. :) – Akasata Akasata Jul 02 '18 at 21:00

1 Answers1

0

Endianness can change between hardwares. A "flag" as you describe is an ok way to keep track of the endianness of a file.

You might want to consider forcing an endianness on your data.

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

The above question answers how to force endianness to your data, which I believe is the better way.

washcloth
  • 2,730
  • 18
  • 29