title: Checking stack usage at compile time
body: <p>Is there a way to know and output the stack size needed by a function at compile time in C ?
  Here is what I would like to know :</p>
  
  <p>Let's take some function :</p>
  
  <pre><code>void foo(int a) {
      char c[5];
      char * s;
      //do something
      return;
  }
  </code></pre>
  
  <p>When compiling this function, I would like to know how much stack space it will consume whent it is called. This might be useful to detect the on stack declaration of a structure hiding a big buffer.</p>
  
  <p>I am looking for something that would print something like this :</p>
  
  <p>file foo.c : function foo stack usage is <code>n</code> bytes</p>
  
  <p>Is there a way not to look at the generated assembly to know that ? Or a limit that can be set for the compiler ?</p>
  
  <p>Update : I am not trying to avoid runtime stack overflow for a given process, I am looking for a way to find before runtime, if a function stack usage, as determined by the compiler, is available as an output of the compilation process.</p>
  
  <p>Let's put it another way : is it possible to know the size of all the objects local to a function ? I guess compiler optimization won't be my friend, because some variable will disappear but a superior limit is fine.</p>