Endian correctness confusion


#1

the example below, should generate the same file, on big- and little-endian processers, right?

const char * const chunk=“abcd”;
FileOutputStream o(f);
o.write (chunk,4);

Am i right?


#2

Endianness only matters when treating memory as a built in type larger than 1 byte. For example, a short, a long, or a double. Since the version of write() you are calling is dealing with bytes, endianness shouldn’t matter.


#3

Thanks. I was a little confused why the WAV-Format Chunks are saved so complicated (as integers), maybe because of easier comparison. (But finally i get it :slight_smile:

inline int chunkName (const char* const name) noexcept { return (int) ByteOrder::littleEndianInt (name); }
out.writeInt (chunkName (“ltxt”));