Skip to main content
vchau.2
Associate III
December 20, 2024
Solved

function depth support

  • December 20, 2024
  • 2 replies
  • 1342 views

Hi All,

I want to know what is maximum function depth supported by STM32F417 in stmcube ide?

how function depth managed by stack pointer? 

Best answer by KnarfB

There is no limit. The stack may overflow at run-time and this is not automatically detected and in your responsibility.

Here is a recursive function:

 

 

int ackermann(int n, int m) {
 if (n == 0)
 return m + 1;
 else if (m == 0)
 return ackermann(n - 1, 1);
 else
 return ackermann(n - 1, ackermann(n, m - 1));
}

 

 

ackermann(3,6) is 509. Calculating this results involves 2.986.490 recursive function calls (without optimizations). Finding the max. stack size used is left an exercise.

Learning abaout the stack in Cortex-M is a covered in books like "Definitve Guide..." by Joseph Yiu and online: 

Happy reading

KnarfB

2 replies

Ozone
Principal
December 20, 2024

This is not exactly "function depth".

But yes, the critical parameter here is stack size, which is part of the specific project settings.
I don't use CubeIDE, so here an example from another toolchain / IDE:

Ozone_0-1734677418484.png

In most cases, stack size is a parameter retrieved or shown during project creation, a.k.a. "project wizard".
Usually a default setting is presented you can edit at that time, or later on.

vchau.2
vchau.2Author
Associate III
December 20, 2024

thanks for quick reply,

but my question in not belong to Stack size or stack over flow,

my Questions is -

1. how many C functions can be call in nested form?

2. How stack manage these nested functions by stack pointers

example:

int main()

{

func_1();

}

void func_1();

{

void func_2();

.

.

 

}

KnarfB
KnarfBBest answer
Super User
December 20, 2024

There is no limit. The stack may overflow at run-time and this is not automatically detected and in your responsibility.

Here is a recursive function:

 

 

int ackermann(int n, int m) {
 if (n == 0)
 return m + 1;
 else if (m == 0)
 return ackermann(n - 1, 1);
 else
 return ackermann(n - 1, ackermann(n, m - 1));
}

 

 

ackermann(3,6) is 509. Calculating this results involves 2.986.490 recursive function calls (without optimizations). Finding the max. stack size used is left an exercise.

Learning abaout the stack in Cortex-M is a covered in books like "Definitve Guide..." by Joseph Yiu and online: 

Happy reading

KnarfB

vchau.2
vchau.2Author
Associate III
December 20, 2024

thanks for sharing such informative links....

that will be helpfull