C++ for Embedded · Interview question

Why is overloading safe to use on a microcontroller when some C++ features aren't?

A strong answer

Because it's resolved entirely at compile time and produces the same machine code you'd write by hand. Overload resolution picks the target function during compilation from the static argument types, then emits a direct call, there's no runtime type information, no dispatch table, no allocation, and no exception machinery involved. So it adds zero code size and zero cycles beyond the call itself, fitting the zero-overhead principle. Contrast that with the features embedded avoids, exceptions (unwind tables, code bloat, non-determinism), RTTI (type metadata), dynamic allocation (fragmentation), all of which have runtime cost or non-determinism. Overloading, like templates and non-virtual methods, is in the "free abstraction" category, so there's no reason to avoid it on a constrained target.

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

Function & Operator Overloading

One name, several type-specific implementations the compiler picks for you, and giving your own types natural operators, without the runtime cost of C's void* or tagged dispatch.

More Function & Operator Overloading questions

Browse all 472 interview questions