title: Purpose of C/C++ Prototypes
body: <p>I was reading wikipedia on C/C++ Prototype statements and I'm confused:</p>
  
  <p>Wikipedia say: "By including the function prototype, you inform the compiler that the function "fac" takes one integer argument and you enable the compiler to catch these kinds of errors."</p>
  
  <p>and uses the below as an example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
   /* 
    * If this prototype is provided, the compiler will catch the error 
    * in main(). If it is omitted, then the error will go unnoticed.
    */
   int fac(int n);              /* Prototype */
  
   int main(void) {             /* Calling function */
       printf("%d\n", fac());   /* ERROR: fac is missing an argument! */
       return 0;
   }
  
   int fac(int n) {             /* Called function  */
       if (n == 0) 
           return 1;
       else 
           return n * fac(n - 1);
  }
  </code></pre>
  
  <p>But the function definition of the called function already includes <em>all</em> the information that the prototype tells the compiler, so why can't the compiler deduce this information from the called function's definition since they contain <em>identical</em> statements/information letter for letter?</p>
  
  <p>What am I missing? Seems like extra work for no obvious gain.</p>
  
  <p><strong>Edit: Thanks guys. I assumed the compilers were multi-pass I guess. I'm spoiled to current languages like Python. It makes sense since it's so old to need some kludges to do things accurately in a single pass. It seems more obvious to me now. Apparently it requires fairly intimate knowledge of how the compiler links and compiles.</strong></p>