Like other comments noted, there is no standard way to determine the stack size of a program. You can, however, calculate the stack size a specific program needs on a given platform with a little hack.
For this, you can keep track of the lowest stack address a local variable in any function had. You then subtract this from the address of the last local variable in the main() function, and you have the maximum stack size (give or take, say: 100 bytes for temporary stack variables needed for expression evaluation).
The following program illustrates this:
#include <stdio.h>
void * lowestStackAddress = ( void * ) 0xFFFFFFFF;
int myFunc( int n )
{
int m;
/**** remember lowest stack address ****/
if ( &m < lowestStackAddress )
lowestStackAddress = &m;
/**** do some arbitrary recursive algorithm the compiler can't optimize away ****/
if ( n == 1 )
return 1;
if ( n % 2 == 1 )
m = n * 3 + 1;
else
m = n / 2;
return myFunc( m );
}
int main ( int argc, char * argv[] )
{
int n;
void * mainStackAddress = ( void * ) &mainStackAddress;
printf( "mainStackAddress=%p\n", mainStackAddress );
n = myFunc( 5 );
printf( "Largest stack size: %d\n",
( char * ) mainStackAddress - ( char * ) lowestStackAddress );
getchar();
return 0;
}
You need to place that check/assignment for lowestStackAddress in every function that doesn't call another function itself.
Pretty ugly hack, and I don't know if this is even applicable because you might not be able to compile all the necessary source code yourself, but it was just a thing that came to my mind.