binary files

J

Jim Langston

are binary files portable?

On the presumption you mean binaray data files, it depends on your
definition of "portable". There may be some issues with things such as
endian if the data is written on a system with, say, big endian and tried to
be read from a system with little endiant and the program does not that that
into account. But, consider, binary data files such as .jpg can be
displayed on both windows and linux systems as well as macs, etc... But, an
os specific program is needed to read the data and display it appropriately.
 
J

James Kanze

what about binary files created in c++?? are they portable?

Whether a file is "portable" or not is independant of whether it
is text or binary. A file is portable to all systems which
understand its format.

Typically, of course, binary files are more portable than text
files, because computer programmers seem to be more aware of the
portability problems involving binary files. But anyone who has
opened a file written under Unix with Notepad knows that text
files aren't very portable. Not to mention when you start
having to deal with different encodings. And of course, if the
target program expects HTML, and you've output LaTeX, there's
going to be a portability problem as well.

C++ itself doesn't make any assumtions about file format. Text
or binary, it's up to the creating program to format. About the
only difference is that C++ does provide formatting and parsing
for the built-in types (e.g. int, double) for a number of
typical text formats, but no formatting or parsing for binary
formats. The historical reason for this is probably that Unix
(where C and C++ grew up) only uses binary formats for a very
few machine dependent files: object files or executables, for
example, which by their very nature aren't portable.
 
M

Michael DOUBEZ

(e-mail address removed) a écrit :
what about binary files created in c++?? are they portable?

That depends on how you create them. Google for "serialization".

Michael
 
L

Lionel B

what about binary files created in c++?? are they portable?

I was being kind of facetious... but not quite. I assume you meant
"binary" as opposed to "text". But computer files really are just 0s and
1s - how one chooses to interpret the 0s and 1s depends on conventions
between the producer and consumer of the data in question. After all, how
portable are "text files"? There are many different conventions (perhaps
read "encodings") for text, of varying degrees of "portability" in the
computer world.

So to answer your question: a "binary" (i.e. *any*) file, whether it be
created in C++ or whatever, is only "portable" insofar as the person/
machine that is going to have to interpret the data it contains knows how
to do so.
 
T

Tim Slattery

what about binary files created in c++?? are they portable?

What do mean by a binary file? Executables created by compiling a C++
program should be portable to another machine running the same or
compatible OS and hardware. You couldn't compile a program on Windows
and run it on a Mac (unless you used a cross-compiler).

Other than that, there are still things to watch out for. Different
hardware and OSs may have different internal representations for
floating point numbers or integers (especially big-little endian
differences). That could make it impossible - or at least quite
difficult - to read a binary file created on a different machine that
the one it was created on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top