Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

6.2.2.3. Stack Overflow

Stack overflow is a common problem in embedded systems, because their limited memory requires that your application have a limited stack size. When your system runs a real-time operating system, each running task has its own stack, increasing the probability of a stack overflow condition. As an example of how this condition may occur, consider a recursive function, such as a function that calculates a factorial value. In a typical implementation of this function, factorial(n) is the result of multiplying the value n by another invocation of the factorial function, factorial(n- 1). For large values of n, this recursive function causes many call stack frames to be stored on the stack, until it eventually overflows before calculating the final function return value.