I'm currently dealing with endianness-related problems.
Let's assume that I have a big-endian file in a big-endian system.
The first value in this file is 2882400152 = 0xABCDEF98
which is an integer 4.
To read that value in an integer 4, _myint4
, I simply do :
mystream.read(reinterpret_cast<char*>(&_myint4), sizeof(_myint4))
The question is : what is the equivalent to read the integer 4 value in the file, in an integer 8, _myint8
?
- for a big-endian file and system ?
- for a little-endian file and system ?
My first guess would be something like that :
mystream.read((reinterpret_cast<char*>(&_myint8))+4, 4); // big-endian file/system
mystream.read(reinterpret_cast<char*>(&_myint8), 4); // little-endian file/system
But I'm not sure at all. What is the good way to do this ?
IMPORTANT : I cannot use a temporary integer 4 value, I need to read directly the integer 4 in _myint8
.