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





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.

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.


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.

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

http://www.abvolt.com
.