[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Sheflug] c++ & mem
> No, I disagree completely. If you're planning on programming in C++, you
> need to test the compiler *with* C++, not C - that means the libraries, etc.
> If you compile that C hello world, it means you have C dev libraries
> installed. Woopee-doo. That's no use if you want to program C++ eventually.
> g++ is gcc anyway, so if you've compiled things on your system before,
> compiling that program tells you nothing.
>
This follows from both Alex's post above and Will's comments. Basically I put
it to a practical test along the lines of "let's actually have a look to see
what the differences are" ... one basic "hello world" using printf, built
with both gcc and g++, and one basic hello world using IOstream.
The results are ... :)
The printf with gcc is a little smaller than the same program built by g++
.. 3080 bytes for C, 4060 for C++. When built with gcc, it links against
libc and libm. When built with g++, it *still* links against libc and libm,
but it also links with libstc++.
The IOstream verseion of hello world is slightly larger again, being 4208
bytes. Despite it being C++ it still links against libc and libm, as well as
libstc++ (as expected).
Running: executing the program gives a better idea of whats going on. With
the basic printf() form, doing ltrace gives the same results for both the gcc
and g++ versions of the code (no point doing an strace ... it's the libraries
we're interested in). The library trace goes simply:
__libc_start_main()
__register_frame_info()
printf()
__deregister_frame_info()
as can be seen, nothing fancy as far a C++ is concerned. But the compiler
works as its producing a binary that runs :)
The iostreams one is different, as you'd expect. The ltrace goes:
__libc_start_main()
__register_frame_info()
ostream::ls()
__deregister_frame_info()
now we can see that there is a little bit of object orientation going on with
the ostream::ls() :) This shows that the object orientation part of the
compiler probably works. What you'd ideally need to do now is write a simple
hello world that uses an object, so you aren't relying on library functions :)
Conclusions: both compilers work :) But how you interpret the results, and
what you are looking for may vary. If writing standard C, then the only
difference I can tell in this far-from-exhaustive study is the the inclusion
of the libstc++ library in the linkage. And it looks like, from the ltrace,
that this isn't used at all if you stick to standard libc calls...it's just
part of the linkage that makes it a C++ program :)
So...
I'll leave these results for analysis, criticism and ridicule :-)
Chris...
--
Chris Johnson \ "If not for me then, do it for yourself. If not
sixie@nccnet.co.uk \ for then do it for the world." -- Stevie Nicks
www.nccnet.co.uk/~sixie/ ~---------------------------------------+
Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \______
---------------------------------------------------------------------
Sheffield Linux User's Group - http://www.sheflug.co.uk
To unsubscribe from this list send mail to
- <sheflug-request [at] vuw.ac.nz> - with the word
"unsubscribe" in the body of the message.
GNU the choice of a complete generation.