Re: C++ vs C compiler on size (Bill Leonard)
12 Jan 1997 11:35:02 -0500

          From comp.compilers

Related articles
C++ vs C compiler on size (1997-01-07)
Re: C++ vs C compiler on size (Arch Robison) (1997-01-09)
Re: C++ vs C compiler on size (1997-01-12)
Re: C++ vs C compiler on size (1997-01-12)
Re: C++ vs C compiler on size (1997-01-12)
Re: C++ vs C compiler on size (Stanley Chow) (1997-01-14)
Re: C++ vs C compiler on size (Joseph Donahue) (1997-01-14)
Re: C++ vs C compiler on size (1997-01-16)
Re: C++ vs C compiler on size (Kurt Svensson) (1997-01-16)
| List of all articles for this month |

From: (Bill Leonard)
Newsgroups: comp.compilers
Date: 12 Jan 1997 11:35:02 -0500
Organization: Harris Computer Systems, Ft. Lauderdale FL
References: 97-01-048
Keywords: C, C++, code (Zhenghao Yeh) writes:
> On average, how much bigger the code generated by C++ compiler than
> C compiler? Well, you may answer that this depends which compiler is
> used and what C++ features are used. Assume we have C code, we use
> both C++ and C compiler. Is the size of the generated code supposed
> to be same?

To make the question meaningful, I think you have add the condition
that the given code is both legal C and legal C++, and has the same
meaning in both languages.

Given that, and given that many C++ compilers can also compile in a
C-only mode, I would expect to get the same object code in both
languages. The size of the executables might be different, however,
due to differences in symbol processing (e.g., name mangling for C++)
for the two languages.

However, if you are comparing two different compilers, I would have no
expectations when comparing the size (or contents) of the object code.
In fact, I wouldn't have any expectations when comparing two different
C compilers!

> How much overhead we have to pay if we need:
> 1. inheritance?
> 2. virtual functions?
> 3. template?

I don't think anyone can answer that definitively -- it depends too
much on the compiler, the machine architecture, and exactly how those
features are being used.

But more importantly, be careful of what you are comparing to. It
seems ridiculous to me to compare a virtual function call to a
non-virtual function call, because they are used for different
purposes! I wouldn't compare those two any more than I would compare
an addition to a division operation.

If you are comparing C++ to C, then you should compare two equivalent
things. For instance, compare a virtual function call to the
*equivalent* C code that would implement the same functionality.

Bill Leonard
Concurrent Computer Corporation
2101 W. Cypress Creek Road
Fort Lauderdale, FL 33309

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.