Mail Archives: djgpp/2002/09/23/20:45:19
From: | MCheu <mpcheu AT yahoo DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: questions/help with c++ compiling
|
Message-ID: | <ftbvou849i9bchtbdmtfjr20cikjpibqje@4ax.com>
|
References: | <F2454wgGLcJqZpiRfRv00003b15 AT hotmail DOT com>
|
X-Newsreader: | Forte Agent 1.92/32.572
|
MIME-Version: | 1.0
|
Lines: | 98
|
Date: | Mon, 23 Sep 2002 20:39:41 -0400
|
NNTP-Posting-Host: | 209.188.65.124
|
X-Trace: | localhost 1032827977 209.188.65.124 (Mon, 23 Sep 2002 18:39:37 MDT)
|
NNTP-Posting-Date: | Mon, 23 Sep 2002 18:39:37 MDT
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
On Mon, 23 Sep 2002 18:10:05 -0400, "Timothy M Boronczyk"
<bluephoenixbeta AT hotmail DOT com> wrote:
<SNIP>
>
>#include <iostream.h>
>int main()
>{
> cout<<"HEY, you, I'm alive! Oh, and Hello World!";
> return 0;
>}
>
<SNIP>
>So here're my quetions:
>
>1) Am I at least using the correct command/syntax to compile a c++ program?
Yes -- sort of.
The standard for C++ is fairly recent. What you used was the old
header style. Most newer books use the new style and some of the
more militant people in certain C++ newsgroups will only accept this
new style as correct. Keep in mind that the old style is deprecated,
meaning it's obsolete, but most compilers still recognize it. There
is, however, no real guarantee that future compilers will continue to
recognize it as correct.
The new header style is something like this:
#include <iostream>
using namespace std;
Developer (that's you) created header files are still used the same
way as before (as far as I know):
#include "myheader.h"
>2) It's obviously done something with hello.cpp, but what exactly did gpp
>do, and what then is the hello.exe file?
First, hello.cpp is the source file. It's what you wrote, and you
can't run it directly. It has to be converted to something the
comptuer can understand. The compiler takes hello.cpp (the source
file) and makes an executable with it. The executable is hello.exe.
It is what you can run and actually get it to do something. Try it...
Specifically, The compiler (gpp or gcc) reads the source file and
makes a machine language object file from it. This is probably
hello.o and may or may not be there depending on compiler settings.
But by itself, the system can't run it, because the OS wouldn't know
what to do with it -- specifically, where to put it in memory, or how
to start it up. For this, you need the Linker to add in a stub -- a
piece of machine code that tells the system what to do with the object
code. This stub is attached to every executable -- it's required.
In addition, the linker also ties in all the libraries that you may
have requested (see headers like iostream). Once everything's all
tied together neatly, you have a runnable executable.
This also addresses your other concern. Specifically that your small
insignificant program is "so huge". There is always going to be
that common code -- the stub, and misc libraries. This is going to
add a fairly constant amount to the size of your exe files. As you
build larger projects, you'll find that the stub becomes less and less
significant as far file size goes. The size of the stub varies from
compiler to compiler.
>
>3) If I were to use a "non-depreciated" header, like gpp suggests, which is
>the iostream.h equivelant... and does the new .h still use the functions
>cout, cin, etc.?
Yup. it's all still there. You don't necessarily have to specify
the namespace at the header... If you don't, however, you will need
to specify it when you call the functions.
ie.
namespace std specified:
cout << "Hello";
namespace unspecified:
std::cout << "Hello";
>I want to say thanks for your help in advance. I admit to being a "newbie,"
>but hey, we've all got to start out somewhere, and with brain like a sponge,
>I'm eager and willing to learn. :)
>
>-Tim
-----------
Thanks
MCheu
- Raw text -