C++ for Embedded · Interview question

Which C++ features are safe on an MCU and which should you avoid?

A strong answer

Safe and idiomatic: classes and encapsulation, RAII for deterministic resource cleanup, templates for compile-time generics (zero runtime cost), references, const/constexpr, and enum class. Avoid or disable: exceptions (-fno-exceptions, they add code size and make timing non-deterministic, and there's often nowhere to recover to on bare metal), RTTI (-fno-rtti, dynamic_cast/typeid add type metadata), dynamic allocation (new/delete and allocating containers like std::vector/std::string, fragmentation and non-determinism, same reasons malloc is avoided in C), and <iostream> (huge code footprint). The guiding principle is that the valuable abstractions are the cheap ones, and the costly features are mostly avoidable without losing C++'s benefits.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

C++ vs C for Embedded

What C++ adds over C on a microcontroller: classes, RAII, templates, references, and the zero-overhead principle that makes those abstractions free.

More C++ vs C for Embedded questions

Browse all 472 interview questions
Which C++ features are safe on an MCU and which should you avoid? | EmbeddedPrep.io