C Programming · Interview question

What happens on a stack overflow, and how does it differ between a desktop and a no-MMU MCU?

A strong answer

A stack overflow is when the stack grows past its allotted region, from unbounded/too-deep recursion or oversized local arrays (or VLAs with a large runtime size). On a desktop, the OS places a guard page just past the stack limit; touching it triggers a fault the OS turns into a clean segfault that terminates the process at the point of overflow, so it's relatively easy to diagnose. On a microcontroller with no MMU, there's no guard page: the stack just keeps growing and silently overwrites whatever memory is adjacent, .bss, the heap, or in an RTOS another task's stack. There's no fault at the moment of corruption; instead you get bizarre, delayed failures far from the root cause. That's why embedded developers size stacks deliberately, avoid deep recursion and large locals, and often fill the stack with a sentinel pattern at boot to measure the high-water mark and detect near-overflows.

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

Stack vs Heap

Where your variables actually live: automatic stack storage vs manual heap allocation, and why returning a pointer to a local is the classic firmware crash.

More Stack vs Heap questions

Browse all 472 interview questions
What happens on a stack overflow, and how does it differ between a desktop and a no-MMU MCU? | EmbeddedPrep.io