On almost every new device project someone asks whether the firmware should be in C or C++. I run an engineering company, so I get pulled into this more often than I expected. Over time I stopped treating it as a language question. A few practical things usually decide it before anyone opens an editor.
1. What does the vendor SDK expect?
Firmware rarely starts from an empty file. You start with the chip vendor's SDK, an RTOS and their drivers. ESP-IDF, Zephyr and most vendor HALs are C and give you C APIs. You can put C++ on top, but then your team has to be comfortable on both sides of that boundary.
When the SDK is C and the device logic is small, we usually stay in C. When the logic grows (several sensors, a connectivity state machine, a versioned protocol to the cloud), wrapping the C APIs in a few C++ classes makes the code easier to read and to test.
2. How big will the code get, and who will maintain it?
The usual objection to C++ on microcontrollers is overhead. In practice it is smaller than people think, and it matters less as the program grows, because in C you end up hand-writing the same abstractions with structs and function pointers. Our blog has a comparison of one LED task written four ways on an Arduino, from flat C to a C++ class: C vs C++ for embedded code: differences and a test.
Maintenance worries me more than bytes. A device that stays on the market for five years will be maintained by people who did not write version one. I would rather give them C++ with clear classes and an agreed feature list than C where the structure only exists in naming conventions.
3. Which C++ features are allowed?
Saying "we use C++" does not tell the team much. On small MCUs we usually switch off exceptions and RTTI, avoid dynamic allocation after start-up and keep an eye on templates that blow up code size. Classes, RAII for peripherals and locks, constexpr, namespaces and strong types for units tend to pay off.
If a team can't agree on that list fairly quickly, I take it as a sign to stay in plain C with clean modules for now.
4. What happens after the device ships?
For a connected product the riskiest code is often the update path: the bootloader, A/B images with rollback, and how the device talks to the cloud when versions differ or the network drops. That part needs careful review and testing on real hardware.
Bootloaders and the lowest layers usually stay in C because that is what the tooling supports. Above that it can go either way. I mostly care that the update path is designed before the first units leave the lab.
5. Who is on the team today?
Often the people decide it. A team of strong C engineers will ship a solid product in C sooner than they will learn to write good C++. A team that already writes modern C++ will be slower if you force everything into C.
My short version
- Small device, C SDK, simple logic, C team: C, with clear modules.
- Growing logic, several engineers, years in the field: C++ on top of the C SDK, with an agreed subset.
- In both cases, plan updates and recovery first and get onto real hardware early.
At Indeema we build firmware on ESP32, STM32, Nordic and other platforms, with FreeRTOS, Zephyr and bare metal, and both approaches have worked for us.
How does your team decide? If you keep a list of allowed C++ features for embedded work, I'd be curious what is on it.
Top comments (0)