Different compilation results not using extern in C vs in C++ : <p>When I declare a global variable in two different source files and only define it in one of the source files, I get different results compiling for C++ than for C. See the following example:</p>

<h1>main.c</h1>

<pre><code>#include &lt;stdio.h&gt;
#include "func.h" // only contains declaration of void print();

int def_var = 10;

int main() {
    printf("%d\n", def_var);
    return 0;
}
</code></pre>

<h1>func.c</h1>

<pre><code>#include &lt;stdio.h&gt;
#include "func.h"

/* extern */int def_var; // extern needed for C++ but not for C?

void print() {
    printf("%d\n", def_var);
}
</code></pre>

<p>I compile with the following commands:</p>

<pre><code>gcc/g++ -c main.c -o main.o
gcc/g++ -c func.c -o func.o
gcc/g++ main.o func.o -o main
</code></pre>

<p>g++/clang++ complain about <code>multiple definition of def_var</code> (this is the behaviour I expected, when not using extern).
gcc/clang compile just fine. (using gcc 7.3.1 and clang 5.0)</p>

<p>According to <a href="http://en.cppreference.com/w/c/language/extern" rel="noreferrer">this link</a>:</p>

<blockquote>
  <p>A tentative definition is a declaration that may or may not act as a definition. If an actual external definition is found earlier or later in the same translation unit, then the tentative definition just acts as a declaration. </p>
</blockquote>

<p>So my variable <code>def_var</code> should be defined at the end of each translation unit and then result in multiple definitions (as it is done for C++). Why is that not the case when compiling with gcc/clang?</p>
