EmbeddedRelated.com
The 2026 Embedded Online Conference
C++ On Embedded Systems

C++ On Embedded Systems

Matt Kline
Still RelevantIntermediate

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.


Summary

This article explains the practical benefits and pitfalls of using C++ for embedded firmware on RTOS and bare-metal targets. It covers language features that improve safety and expressiveness (classes, RAII, templates) and gives advice on toolchain, runtime, and library choices needed to run C++ in constrained embedded environments.

Key Takeaways

  • Adopt RAII and scoped objects to simplify resource management and reduce leaks on bare-metal and RTOS systems.
  • Disable or carefully configure exceptions and RTTI, and know how to provide minimal runtime hooks to avoid unwanted system dependencies.
  • Configure the toolchain and linker (startup code, newlib/libgcc/libstdc++ selection) to include only the runtime pieces you need.
  • Measure and control template and inline use to manage code size and flash/ROM impact.
  • Use a disciplined subset of C++ and test the resulting runtime behavior on target hardware early in the port.

Who Should Read This

Embedded firmware engineers (comfortable with C) who are evaluating or migrating to C++ for RTOS or bare-metal microcontroller projects and need practical guidance on runtime and toolchain trade-offs.

Still RelevantIntermediate

Topics

Firmware DesignRTOSBare-Metal ProgrammingARM Cortex-M

Related Documents


The 2026 Embedded Online Conference