[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] C++ on AVR 90S8515
From: |
Joerg Wunsch |
Subject: |
Re: [avr-gcc-list] C++ on AVR 90S8515 |
Date: |
Tue, 25 Jun 2002 11:52:42 +0200 |
User-agent: |
Mutt/1.2.5i |
As Stumpf Michael wrote:
> > Why depends the use of C++ classes on available memory?
>
> Because implementation of classes takes some effort :
>
> - for every class there has to be a table of member functions (the so
> called vtbl)
Only if there are virtual methods in this class.
> - every member function gets an implicit argument, the 'this' pointer
OK, that occupies a couple of registers. However, if you implement
similar problems in C, you most likely won't avoid passing something
similar as a pointer to an object as well.
> - if a class uses virtual functions then ...
...of course resource consumption will increase a lot. ;-) But then,
if someone is using "true OO programming", he must be prepared to pay
for it. Unlike languages like Java, C++ leaves it to the programmer
whether the true OO model (late binding) is used or whether everything
is bound at compile-time.
> - if templates are used there maybe functions generated for every
> combination of argument type - ...
Sure. But if you use C where you don't have templates, you just have
to write it multiple times should you need the functionality.
> And implementing C++ means all or nothing, not only a subset.
But the generated code only contains the subset required, even though
the implementation is complete and were able to produce the full
complexity. That's why i wrote that one needs to be overly cautious
to avoid waste of memory and code. (It's usually a good idea to
verify the compiled assembler code.)
> One could argue that a smart compiler could resolve the overhead for
> simple classes, but regarding the origin of gcc I doubt ...
Why do you doubt instead of looking at the generated code?
--
J"org Wunsch Unix support engineer
address@hidden http://www.interface-systems.de/~j/
avr-gcc-list at http://avr1.org