Re: which object orient language is most suitable for embedded programming?



"Vladimir Vassilevsky" <antispam_bogus@xxxxxxxxxxx> wrote in message
news:NdF9h.24982$yl4.13528@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx


David Brown wrote:

Two features of C++ can produce a lot of overhead in C++ programs,
especially for small systems - exceptions and RTTI. If you can disable
them in the compiler (and C++ compilers I have seen let you do that),
then the C++ compiler should generate pretty much identical code for a C
function compiled as either C or C++. In other words, no overhead. (Of
course, if you make use of exceptions, then the overhead can be worth
it.)

The size of C++ startup code is comparable to the size of a small
application.

No true. I have implemented code for a small scientific instrument that uses
C++. I wrote the startup code myself based on the C startup because I needed
to init hardware in C earlier than zeroing BSS. The additional code needed
to support C++ was a scan of a table of static constructors before main and
destructors after. In fact the tables are empty in my case, so that overhead
is wasted. I used GCC for ARM. Note, as discussed earlier this is without
RTTI and exceptions - if you're using those then it really is an apples and
oranges comparison.

However, C++ makes it easier to accidentally generate very inefficient
code - even easier than C does. C has a few pitfalls for the unwary
embedded programmer, such as using "printf" and linking in a (relatively)
huge floating point library. C++ has many more - for example, if you add
a virtual destructor to your classes, because that's what you learned on
your C++ course, your small classes are going to be an order of magnitude
bigger and slower on a limited processor.

There are also compiler related inefficiencies such as the tables of
pointers to functions have to be placed in RAM rather then in ROM, etc.

Why? The tables of pointers to functions, commonly called vtables, can, and
are, stored in ROM. Each object that has virtual member functions has a
pointer to this table in RAM. But presumably if you have a vtable then you
are using the indirect function calls for a reason, which would require
something like function pointers or switches otherwise.

Writing efficient C++ code for small micros is certainly possible, and
I've seen some very neat examples (like an 8-bit integer class for avrgcc
that produced better code than an int8, because it avoided int
promotions), but you need to know a lot about the compiler, the language,
and the target to get efficient code.

To me, the whole point of using C++ is avoiding the unnecessary technical
knowledge about minor details. It is sad to see how much time is spent
learning the features of the CPU/compiler/board/OS and fighting the stupid
bugs instead of the actual development of the application.

Perhaps. It is never a good idea to think that you an get away with an
inferior programmer by providing a 'better' programming language.

Peter


.