2 ms·
If you are writing binary data from memory, _and_ want to make sure any system can read it no matter what endianness it uses, you might need something like this
by theamk 4y ago
If you are writing binary data from memory, _and_ want to make sure any system can read it no matter what endianness it uses, you might need something like this:
buf[0] = (data >> 24) & 0xFF;
buf[1] = (data >> 16) & 0xFF;
buf[2] = (data >> 8) & 0xFF;
buf[3] = data & 0xFF;
and if you want this code to work on all systems (including wide-char ones), you need to make sure fwrite truncates too.