This is the mail archive of the
c++-embedded@sourceware.cygnus.com
mailing list .
Re: biggest deterrant to using C++?
- To: <c++-embedded at cygnus dot com>
- Subject: Re: biggest deterrant to using C++?
- From: "Michael Bruck" <mbruck at rft dot de>
- Date: Mon, 24 Aug 1998 03:37:50 +0200
One of my bigger problems with using C++ in embedded projects is the
way ctors are handled. When you have global class variables the
compiler (in my case egcs) generates lots of constructor/destructor
calls for them, where they are completely uneccessary. For example:
struct general_thing {
int weight;
general_thing(int _weight = 0) : weight(_weight) {}
virtual bool get() = 0;
};
struct atom_bomb : public general_thing {
long price;
atom_bomb(long _price, int _weight = 1000) : price(_price),
general_thing(_weight) {}
virtual bool get();
};
const atom_bomb my_bomb(50, 100);
I would like to have my_bomb somewhere in the ROM. And the example above
should not generate any code as long as I don't call the constructors in
another context. What happens is, that the compiler always generates
a function for each source file that calls all the constructors and
then generates a section that contains the pointer to that function.
These sections from all files are then linked together into a table of
function pointers and the init-functions of all global objects are
called at program startup through this table. This is ok if my
constructors are doing something other than just copying around values.
This would cause in most situations just some overhead,
but if you want to use ROM it's impossible to use (virtual) classes.
Micha