> I have played around with my own small stream implementation and it
> worked at least on
> one platform. But it takes a lot work to implement all the data types
> to be loaded/saved.
> My question: Are the standard ifstream/ofstream (binary) platform
> independant ?
The definition is platform independent. Implementations may or may not
be platform dependent.
However, if I understand your question correctly, you are also asking
whether a single codebase can read back binary data written on another
platform.
In general, that is not possible because of:
- differences in character encoding between computers
- differences in endianness <http://en.wikipedia.org/wiki/Endianness>
- differences in the sizes of standard C datatypes such as int and short
- differences in the format of standard C datatypes float and double
- differences in the way compilers lay out structures and classes in
memory
(this list probably is incomplete)
It is not hard to overcome all of these, but doing so does involve some
tedious work (lots of work, if you do not plan ahead, or if the
platforms involved differ greatly in some features you want to use)
Reinder
lothar.behrens@lollisoft.de - 26 Jan 2006 22:06 GMT
Yes,
until now, I have seen, that they have differences. Thus my first tests
failed. Then I have tested
ifstream and ofstream classes, that would work at least on non binary
mode in eight bit format.
(cat test.txt shows up no differences between my Mac and an Intel Linux
box)
This is a beginning and in my design I have encapsulated those stream
classes. So I am able to
change this later or use different variants. I know of endianness, I
would propably use functions,
that handle these issues like socket functions htons and htonl.
There may be others to be used or libraries that address these issues.
Lothar