Re: C++ vs C compiler on size

jlilley@empathy.com (John Lilley)
12 Jan 1997 11:49:48 -0500

          From comp.compilers

Related articles
C++ vs C compiler on size yeh@netcom.com (1997-01-07)
Re: C++ vs C compiler on size robison@kai.com (Arch Robison) (1997-01-09)
Re: C++ vs C compiler on size fjh@mundook.cs.mu.OZ.AU (1997-01-12)
Re: C++ vs C compiler on size bill@amber.ssd.csd.harris.com (1997-01-12)
Re: C++ vs C compiler on size jlilley@empathy.com (1997-01-12)
Re: C++ vs C compiler on size schow@nortel.ca (Stanley Chow) (1997-01-14)
Re: C++ vs C compiler on size jwdonah@ibm.net (Joseph Donahue) (1997-01-14)
Re: C++ vs C compiler on size aeb@saltfarm.bt.co.uk (1997-01-16)
Re: C++ vs C compiler on size edi-c@algonet.se (Kurt Svensson) (1997-01-16)
| List of all articles for this month |
From: jlilley@empathy.com (John Lilley)
Newsgroups: comp.compilers
Date: 12 Jan 1997 11:49:48 -0500
Organization: Nerds for Hire, Inc.
References: 97-01-048 97-01-058
Keywords: C, C++, performance

yeh@netcom.com writes:
>On average, how much bigger the code generated by C++ compiler than C
>compiler?


Hey, nice reply! I love it when someone takes the times to write small
articles that really explain the problem.


Arch Robison wrote:
> [1] Separate discussion issue: Is it theoretically possible for a C++
> compiler to always generate machine code linear in the size of the
> source? If so, is the theoretical implementation practical?


Gee, I know we're gonna open up a big long thread with this one...
Theoretically, of course you can ;) You generate an executable that
contains a C++ interpreter, which is presumably of fixed size, and the
source code. Not very practical though. I am guessing when I say
that it can be done practically as well, given that template expansion
usually results in very similar sets of code that a plausibly
intelligent compiler/linker could merge the similar cases. But I'm
grasping... The complexity of the type interactions in the template
code, make it so darn hard to merge the resultant specializations.


> [2] Perhaps someone reading this can provide references on fat-reduced
> use of templates?


Mogens Hansen has a great article in the Jan 97 C++ Report on "Ways to
reduce code bloat from containers", which details some wrappers around
STL containers that work for a restricted family of types (e.g., all
derived from one base or all pointers). Best of all I think that you
can extrapolate this technique to other template domains (like
reference-counted pionters) to acheive similar results. Of course,
the tradeoff is that you lose a little bit of type-safety, but with
some care even that can be mitigated.


john lilley
--


Post a followup to this message

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