Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / January 2006



Tip: Looking for answers? Try searching our database.

ifstream and ofstream portability

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lothar.behrens@lollisoft.de - 25 Jan 2006 06:13 GMT
Hi,

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 ?

I like to use it on Wintel/Mac/Linunx.

Thanks, Lothar
Reinder Verlinde - 26 Jan 2006 21:18 GMT
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.