C++ On Embedded Systems
This October, my team at work switched from C to C++ for embedded firmware development. Many of its features, including classes, automatic resource cleanup, parametric polymorphism, and additional type safety are just as useful on an RTOS or bare metal as they are on a desktop running a general-purpose OS. Using C++ lets us write safer, more expressive firmware.
C++'s automagic is a double-edged sword, however. Some language features depend on system facilities that we don't want to provide in embedded environments.* Wrangling the toolchain can also be difficult. We don't want to completely discard libgcc and libstdc++ since they provide vital facilities like memcpy, atomic operations, and hardware-specific floating-point functions, but we must avoid certain parts of them.
This guide is a short attempt to codify what we've learned while moving our firmware to C++. Hopefully it provides a solid primer.