Myths
An overview of myths and prejudices about C++ in embedded programming and what are the reasons behind them.
We'll cover the following
As I started working in an embedded environment, I was astonished that there was so much prejudice against the usage of C++ in embedded programming. Most of them are based on the wrong understanding of the C++ programming language.
Some Common Myths
- Templates cause code bloat
- Objects have to be created on the heap
- Exceptions are expensive
- C++ is slow and needs too much memory
- C++ is too dangerous in safety-critical systems
- You must write object-oriented code in C++
- C++ can only be used for applications
- The
iostream
library is too big; the STL library too slow
In summation:
C++ is a cute toy but it cannot handle the challenging tasks.
Prejudices
The list of prejudice is long consisting partially of half-truth and untruth statements often stated by experienced C programmers. I will only refer to the untruth statements. The half-truth statements are, to a large extent, questions due to the right usage of C++ and, to a small extent, questions of the implementation of the core and the libraries of C++.
-
Objects must live on the heap.
- Objects can be created on the stack or at an arbitrary position with the help of placement new.
-
C++ is too dangerous in safety-critical systems
- Of course, it depends on the experience of the developer. But whoever uses C strings instead of C++ strings; uses C arrays instead of C++ arrays; uses macros instead of constant expressions or templates, can not argue that C++ is not well suited for safety-critical systems. Honestly, the contrary holds. C++ has a lot to offer in safety-critical systems.
-
You must program object-oriented in C++
- C++ is a multi-paradigm language, meaning you can solve your problem in an object-oriented, structured, functional, generic, or generative style.
-
C++ can only be used for applications
- C++ can be used for many different kinds of products for example, fire extinguishers, defibrillators, and cars.
Get hands-on with 1400+ tech skills courses.