April 3rd, 2012, 02:15 AM
Embedded Programming in C++?
So I have a basic question:
How good is C++ for embedded systems? I have read about Embedded C++(a subset of C++) but I heard it is a dead project?
I have an embedded project written in assembler and C. And I am wondering what to do with it. One option is to rewrite the system with an OO approach. (the code is kinda messy now).
So your opinions on this matter will be very appreciated
I did benchmark testing of two programs that manipulated character strings, one written in C and optimized for speed using char pointers; the other was the first program converted to C++ and using the String class. The C++ code ran 2.5 times as fast as the C code. Its source was 87 lines of code, vs. 252 lines of code for the C version. However, the executable was 3.3KB larger.
Originally Posted by KansaiRobot
However, this benchmark testing was done on a 32-bit desktop computer. So it
may or may not apply to an embedded system.
The point is you need to do benchmark testing on your embedded system's processor in order to find the answer to your question. The tests should include ONLY the kinds of structures and operations your embedded application requires.
The widespread availability of C and C++ compilers allow you to use the same source code to compile benchmark tests for whatever processor your embedded system uses, provided it doesn't run out of RAM (which would necessarily open a whole new can of worms, dynamic memory allocation/deallocation). MIght not matter if C++ code runs faster if you have to buy more RAM to run it in.
Just my thoughts.