Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: binary exec...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 17 of 18 Topic 45804 of 47006
Post > Topic >>

Re: binary executable

by James Kanze <james.kanze@[EMAIL PROTECTED] > May 9, 2008 at 06:07 AM

On May 8, 4:58 pm, Sherman Pendley <spamt...@[EMAIL PROTECTED]
> wrote:
> Erwin Moller <hi.steven...@[EMAIL PROTECTED]
> 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
written in.

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
character code.

--
James Kanze (GABI Software)             email:james.kanze@[EMAIL PROTECTED]
 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
 




 18 Posts in Topic:
binary executable
Erwin Moller <hi.steve  2008-05-07 19:20:04 
Re: binary executable
"Victor Bazarov"  2008-05-07 22:50:09 
Re: binary executable
Erwin Moller <hi.steve  2008-05-07 21:04:13 
Re: binary executable
Ian Collins <ian-news@  2008-05-08 16:08:08 
Re: binary executable
Erwin Moller <hi.steve  2008-05-07 21:34:10 
Re: binary executable
Ian Collins <ian-news@  2008-05-08 16:42:32 
Re: binary executable
Joe Greer <jgreer@[EMA  2008-05-08 18:44:22 
Re: binary executable
"Victor Bazarov"  2008-05-08 13:03:23 
Re: binary executable
ram@[EMAIL PROTECTED] (S  2008-05-08 17:16:44 
Re: binary executable
Daniel Pitts <newsgrou  2008-05-08 18:24:51 
Re: binary executable
Krice <paulkp@[EMAIL P  2008-05-08 03:36:22 
Re: binary executable
Lionel B <me@[EMAIL PR  2008-05-08 11:44:57 
Re: binary executable
Sherman Pendley <spamt  2008-05-08 10:58:10 
Re: binary executable
Krice <paulkp@[EMAIL P  2008-05-08 10:20:17 
Re: binary executable
"robertwessel2@[EMAI  2008-05-08 16:02:02 
Re: binary executable
soscpd <soscpd@[EMAIL   2008-05-09 00:55:53 
Re: binary executable
James Kanze <james.kan  2008-05-09 06:07:46 
Re: binary executable
Lionel B <me@[EMAIL PR  2008-05-09 14:07:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 2:00:17 CDT 2008.