richard_damon wrote on Saturday, March 05, 2016:
Rum, difinitively figuirng out how much stack a general program/task will take is a ‘hard’ task, and often the best choise is to run it (over a variety of input conditions) and measure it, and sometimes add a safety factor in case you missed a path.
If the program doesn’t use recursion, than some compilers/linkers will have an option to compute the worse case stack usage of a function if it meets some basic limits. You can also do this by hand, but you may need a bit of help from the compiler.
You can estimate the stack needed by a function by adding up the size of all the local variables and parameters it uses, adding a bit for temporaries needed, and call frames, and then adding what is needed by the things it calls (and the things they call and so on). You may have to guess on the requirements for library functions, but this is normally not the major usage.