title: Sanity of Headers
body: <p>I'm just starting to teach C++, coming from some other languages. I am wishing there were some way to consistently check the API created by a (student) file. </p>
  
  <p>Suppose a student submits this file:</p>
  
  <pre><code>// this is stu.cpp
  #include &lt;iostream&gt;
  using namespace std;
  double x(int y) {return y+0.5;}
  </code></pre>
  
  <p>Actually, suppose I asked the student to define some other function int x(int). I would like to be able to check this by running this code:</p>
  
  <pre><code>// this is stu.h
  int x(int);
  
  // this is gra.cpp 
  #include "stu.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  int main() {
    cout &lt;&lt; x(0); // test their code
  }
  </code></pre>
  
  <p>So I am trying to see if the student's implementation matched the required interface, and testing it on input 0. I would have hoped this would not compile. But when I do</p>
  
  <pre><code>g++ -Wall -Wconversion *.cpp -o gra
  ./gra
  </code></pre>
  
  <p>It compiles and runs without crashing, giving output 0. This remains true even if I compile the two files separately and link them after.</p>
  
  <p>I know that <code>nm</code> doesn't list return types. Is that the same reason that we can link together two files when the return values don't match? Is there any sane way to test this? (Like are there compile-time typeof assertions?)</p>
  
  <p>Or is this a specific bug because of int and double being interconvertible? Are there additionall compiler options that could catch this?</p>