|[2 earlier articles]|
|Re: C++ vs C compiler on size firstname.lastname@example.org.OZ.AU (1997-01-12)|
|Re: C++ vs C compiler on size email@example.com (1997-01-12)|
|Re: C++ vs C compiler on size firstname.lastname@example.org (1997-01-12)|
|Re: C++ vs C compiler on size email@example.com (Stanley Chow) (1997-01-14)|
|Re: C++ vs C compiler on size firstname.lastname@example.org (Joseph Donahue) (1997-01-14)|
|Re: C++ vs C compiler on size email@example.com (1997-01-16)|
|Re: C++ vs C compiler on size firstname.lastname@example.org (Kurt Svensson) (1997-01-16)|
|From:||Kurt Svensson <email@example.com>|
|Date:||16 Jan 1997 11:20:02 -0500|
|Organization:||AlgoNet Public Access Node, Stockholm|
|Keywords:||C, C++, performance|
firstname.lastname@example.org (Zhenghao Yeh) writes: > Hi!
> 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?
> If the answer is positive. Then here is the interesting question:
> How much overhead we have to pay if we need:
> 1. inheritance?
> 2. virtual functions?
> 3. template?
> - Yeh
The question above, to my experience, resulted in the following:
I wrote a "high level" (~80% C grammar) C compiler/interpreter
system. The language was ca: 90% C and included embedded SQL and some
special datatypes and corresponding builtin-functions for special
purposes. Parser use recursive descent - no compiler/compiler tools
used. The compiler I used was Watcom for MS-DOS and 16-bit code was
generated. Later the system was completely rewritten in C++ for
Win95/NT (generating 32-bit code) using Visual C++. The new
compiler/interpreter has a more C like grammar (~90% C) and a more
efficient interpreter and some 10% more builtin functions.
The experience (absolutely not scientifically proved) was:
System written in C
- 30.000 (non-empty and non-comment) lines of code
- Executable sizes: compiler 130K, interpreter 160K
- Efficency factor(speed etc.): 1
- Extensive use of malloc/free
System written in C++
- 20.000 (non-empty and non-comment) lines of code
- Executable sizes: compiler 120K, interpreter 150K
- Efficency factor (speed etc.): 3
- Extensive use of new/delete
- Use of inheritance and virtual functions
- No template usage
The system written in C++ is more maintainable and easier to
understand since the class-structure forced me not to "cheat" (which
sometimes is tempting for C-programmers even if they may have high
ideals). Since the compiler and the interpreter is declared as classes
they could easily instanciated within other appilactions, which made
the product more useful (integrated in IDE). Furthermore I got the
intuitive impression that by using C++ I could concentrate more on the
system structure and less on the "coding".
A final question:
Isn't it easier to change (cut and paste) a program which uses templates to
compile type data structures/functions than the other way around?
Return to the
Search the comp.compilers archives again.