PC vs Mac - Reading and Writing Integers
BlitzMax Forums/BlitzMax Programming/PC vs Mac - Reading and Writing Integers
| ||
On a PC when I write a variable to a file as an integer it retains its value when the file is loaded up again. But when I move the code to my Mac PowerPC its an entirely different value. Is this a bug? |
| ||
PPC uses Big-Endian, X86 uses Little-Endian - see Endianness for more details :-) Basically, the byte-order is reversed. There are TStreams which support different endianness, so you can use those to ensure that the data is loaded/saved in the same way on all platforms. |
| ||
right, I'm looking at the endian stream functions now... could someone please show me how I could use these? the documentation lacks samples :P |
| ||
Create your stream as usual, but then push it into either LittleEndianStream() or BigEndianStream(). Those functions return a new TStream which wraps your original stream, and applies endian conversion if necessary. So, possibly something like : Local myfile:TStream = LittleEndianStream(WriteStream("myfile.txt")) myfile.WriteInt(12345) myfile.Close() |
| ||
Pick either little or big endian stream (arbitrary choice), and then always use that type for every file operation. Problem solved ;D |
| ||
alrighty, thanks! I'll give it a go :) |