We made very good experience with C++ on embedded systems even for
time critical tasks.
For our system we restricted the C++ features that are allowed.
Those are:
- no dynamic memory allocation (no new, delete, malloc, free etc.)
- no exceptions
- no run time type information
- no virtual functions
- no templates
Some of the restrictions were due to the first platform we used
(compiler did not support templates) others were choosen to
increase robustness and speed.
The resulting software is very modular and and code is easy to read.
We almost never had any of those typical C memory access errors...
The great benefits of C++ over C in this projects are:
- excessive usage of references instead of pointers makes the code
very robust
- excessive usage of const classifiers avoids mis-usage of objects
- class access rights + lightweight inline methods (set, get) assure
protection of internal module variables. Old projects were full of
those evil extern declarations...
- constructors assure proper initialized modules
- all of those features above come with virtual no runtime overhead.
One of the disadvantage of C++ is a slightly greater memory footprint
because C++ environment initialization is more sophisticated...
I really like the beauty of our lightwight wrappers for hardware
interfaces. Almost no runtime-overhead, intuitive usage, and very
robust against abuse at the same time. Much better than anything
that you can achieve in C.
Our experience with C++ on embedded systems were so good that we use C
only for those platform that does not provide a proper C++ compiler.