title: C++ by-reference argument and C linkage
body: <p>I have encountered a working (with XLC8 and MSFT9 compilers) piece of code, containing a C++ file with a function defined with C linkage and a reference argument. This bugs me, as references are C++ only. The function in question is called from C code, where it is declared as taking a pointer argument to the same type in place of the reference argument.</p>
  
  <p><strong>Simplified example</strong>:</p>
  
  <p><em>C++ file</em>:</p>
  
  <pre><code>extern "C" void f(int &amp;i)
  {
      i++;
  }
  </code></pre>
  
  <p><em>C file</em>:</p>
  
  <pre><code>void f(int *);
  
  int main()
  {
      int a = 2;
      f(&amp;a);
      printf("%d\n", a);  /* Prints 3 */
  }
  </code></pre>
  
  <p>Now, the word on the street is that most C++ compilers, under the hood, implement references just like a pointer. Is it like that and just pure luck the reason this code works or does it say somewhere in the C++ specification what the result is when you define a function with a reference argument and C linkage? I haven't been able to find any information on this.</p>