I'm interested in compiling a list of c++ features that are not advisable for use in embedded systems (and which may cause people to recommend c over c++). Please try to add why if you know, or add your why to others' answers.
Here's one for a start (the only one I know)
Embedded C uses most of the syntax and semantics of standard C, e.g., main() function, variable definition, datatype declaration, conditional statements (if, switch case), loops (while, for), functions, arrays and strings, structures and union, bit operations, macros, etc.
C provides optimized machine instructions for the given input, which increases the performance of the embedded system. Most of the high-level languages rely on libraries, hence they require more memory which is a major challenge in embedded systems.
Experts say myths have often existed about using C++ for embedded systems. Myths include that C++ performs too slowly. That's not true with properly written C++ code. Reality: Engineers can avoid bloated machine code with C++, and the language can run as quickly and efficiently as C.
there are two answers to this: Any programming language that is “Turing Complete” (almost every programming language is) - can be used to write anything that any other “Turing complete” language can do…so, there is nothing that can be written in C++ that cannot be written in C (or Java or Python or assembly code or….
The Joint Strike Fighter Coding Standards here: http://www2.research.att.com/~bs/JSF-AV-rules.pdf are a pretty good overview of how to use C++ for embedded programming.
The ban on Dynamic Polymorphism is a holdover from the 90s, and has no rational basis. It takes no longer to call a virtual function than it does to do a switch and a call. If you are going to avoid virtual function calls, you might as well be using C.
Certain features require run-time support, so if you miss the required support, you should avoid those features. In particular, the following features usually need extra run-time support:
People also usually mention templates, but they are only an advanced macro facility -- so you can freely use them in embedded systems. Still, you might want to avoid them since they can lead to code bloat after compilation.
Your embedded system should come with documentation saying what, if any, run-time support for C++ (and otherwise) is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With