Embedded Systems & Firmware
On a small microcontroller without an MMU, what should be kept in mind about excessive stack use?
- AThe stack grows automatically without limit, so there is nothing to worry about
- BA stack overflow always shows an error screen
- CStack overflow may not be detected immediately and can silently corrupt neighboring data, so avoid deep recursion and large local arrays and estimate usage
Show answer and explanation
Answer: C. Stack overflow may not be detected immediately and can silently corrupt neighboring data, so avoid deep recursion and large local arrays and estimate usage
A PC OS places a no-access page beyond the stack to detect overflow, but microcontrollers without an MMU often lack that mechanism, and an overflowing stack silently overwrites whatever variables lie beyond it. The symptoms appear elsewhere, making the cause hard to track down. Developers avoid deep recursion and large local arrays, estimate maximum usage with tools, or write a marker pattern at the stack's end and check whether it has been overwritten.
- A. Stack size is limited.
- B. There is no mechanism to display an error screen.
- C. Correct. It tends to cause mysterious bugs.