This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ vs. C asm/object file size


Alexandre Oliva wrote:

> On Jan 11, 1999, Benjamin Scherrey <scherrey@gte.net> wrote:
>
> > Turns out both g++ and gcc product IDENTICAL assembly code and the
> > files are the same size! Please explain these results to me.
>
> Are you compiling the same .cc/.cpp file with gcc and g++?  Remember
> that gcc will deduce the language from the extension of the file, so
> it might be running the C++ compiler in both cases, even though you
> expected it to compile as C when running gcc.  The .c extension, OTOH,
> will be interpreted as a C source by gcc and as a C++ source by g++.

    The code is actually linux kernel code with .h and .c extensions. I've
gone into some of the headers (and source files) and renamed variables
named "new" and corrected a lot of other warnings and errors. I do no
detection of whether the C++ compiler is being called (ala #ifdef
__cplusplus) so the exact same code is compiled by both compilers.

> If this is not the case, maybe you're not talking about object size,
> but executable size.  Indeed, g++ automatically links in the C++
> standard library, that may increase the size of a program even if you
> have a shared libstdc++.

    Since I'm not to the point of actually getting an executable I'm
talking only about the resulting .o files. Don't think that any external
libraries are being brought in because I'm compiling into a separate .o
file for each .c file.

> Another option that is worth considering is whether you're generating
> exception information in both languages.  Their generation is enabled
> by default for C++, but I think it's disabled by default for C.

    This is a possibility. My command line arguments are identical so I'll
go and try to turn off exceptions explicitly. However, wouldn't the
resulting asm code (when I use the -S option) be different if exception
handling were present?

    FWIW - anyone following the linux kernel list might notice that I'm
pushing to get the kernel into a state where it is buildable by C++ - NOT
rewrite it in C++. My hope is that we'd immediately gain the benefit of
its strong type checking without paying any performance or size penalty.
This would also allow the inclusion of C++ features in the future as the
need arises and the compiler generates more efficient code. My purpose of
this exercise is to confirm (as claimed) or disprove the notion that a C++
compiler (specifically egcs) will generate bigger, slower programs from
the exact same source code. As some of you may recall, an effort was made
a long while back to build the linux kernel with a previous version of g++
which suffered from an immature compiler, language standard, and, frankly,
developers who were inexperienced using C++ is performance-intensive
applications. I think that the state of g++ has been dramatically improved
by the egcs team and that the release of kernel 2.2 would be a better base
to add this as a 2.3 feature.

    regards & later,

        Ben Scherrey


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]