Re: binary executable
On May 8, 4:58 pm, Sherman Pendley <spamt...@dot-app.org> wrote:
Erwin Moller <hi.steven...@gmail.com> writes:
Why is a binary file executable? Is any binary file
executable? Is only binary file executable? Are all
executable files binary?
Some systems distinguish between text and non-text (i.e.
binary) files. Not all do. The ones that do, will perform
various text translations when writing to a text file.
If the system distinguishes, then the C++ library will likely do
more than just text translations---you probably won't be able to
open a file unless the mode corresponds to the one it was
A lot of systems have conventions concerning what goes into a
text file, even if the system itself doesn't have different file
types for binary and text. In such cases, the standard library
will normally ensure a translation between the system's
conventions and those imposed by the C++ standard. (Also:
because they are conventions, and not part of the system, they
are often a little bit vague. Under Windows, for example, some
programs treat the sequence 0x0D,0x0A as a line terminator,
others as a line separator.)
As a general rule, a file is considered "text" if its contents
can be interpreted as printable characters, plus a few control
characters such as new line, in some encoding, and 2) it
conforms more or less to the system conventions with regards to
things like how newline and end of file are represented.
Although even 2 is somewhat uncertain: most Windows programs
I've seen consider text files from Unix to be text, even if they
don't conform to the Windows convention for new line. And a
growing number of Unix programs can handle Windows conventions.
Anything which isn't considered "text" is considered "binary".
What is the connection between the attribute of binary and
that of executable?
There is none. What makes a file "binary" is not its contents,
but whether or not you included ios::binary in the optional
flags argument to fstream::open.
At one level. At the system level, of course, different
criteria apply, see above.
And again, the distinction as to what is executable and what
isn't isn't always clear: under Unix, there's an executable mode
bit, but not all files on which is is set will be executable.
For that matter: if I generate a .exe file with VC++, it's
really an executable, right? Even if I do so on a shared mount,
and am looking at it under Solaris? Are my bash shell scripts
executable even if I mount the file system on a machine on which
bash isn't installed. (Don't have any here, but Posix only
requires the Korn shell---and one could imagine thus that a bash
shell script be executable on some machines running Solaris, but
not on others.)
On systems that care, you can open a file that has text in it
as binary to avoid the translations that would happen if you
opened it as text.
Again, you're playing with language: the distinction text/binary
has a different meaning with regards to the C++ standard library
than it does in general use. And just because you opened a file
in binary doesn't mean that none of the text related
translations will occur; some depend on the mode of open, but
others (e.g. code translation) depend on the imbued locale.
You can also do the opposite, but that's rarely useful;
text-mode translations generally FUBAR any binary data.
Yes. Historically, binary meant transparent. That convention
was broken by the C++ committee, however.
And of course, the open mode doesn't really affect how you
interpret the data in your program. Although it doesn't
generally make sense to do so, you can always interpret the
binary value of a char variable as binary data, rather than as a
James Kanze (GABI Software) email:email@example.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34