<p><code>extern</code> before function prototypes does not have any effect. If it were a variable, it’d be needed to specify that the variable was declared somewhere else.</p>

<pre><code>void noui_connect();

void noui_connect() {/*something*/}
</code></pre>

<p>^^^The compiler can easily find which is the prototype and which is the implementation of the same function. However,</p>

<pre><code>// main.h
int a;
// main.c
#include "main.h"
int a = 5;
// util.c
#include "main.h"
</code></pre>

<p>^^^The compiler <em>might</em> create two symbols. One in <code>main.c</code>, one in <code>util.c</code>. To prevent creation of another variable, the <code>extern</code> keyword is used to leave the variable to the linker, the final step at compiling.</p>

<p>On the contrary, the function prototypes, not the implementations are put in header files, which are always left to the linker. Because that's the way function prototypes are designed, they don't need <code>extern</code>.</p>

<p>If you see <code>extern</code> before function prototypes, that's pure coding style, probably to be consistent with other <code>extern</code> variables.</p>

CC BY-SA 4.0
2018-08-31T11:17:15.457Z
Not just consistency, but also clarity. It explicitly signifies to the programmer "The function is not being defined here". Even though it is obvious to the compiler does not mean it must be obvious to developers.
Pieter Wuille
CC BY-SA 4.0
2018-08-31T10:23:35.923Z
2018-08-31T10:48:18.567Z
2018-08-31T10:48:18.567Z
MCCCS
<p>When I review the Bitcoin Core source code, I see the <code>noui.h</code> as a header file, but the method <code>noui_connect</code> has been declared with the keyword <code>extern</code>. I think there is no need to do this.</p>

<p><code>extern void noui_connect();</code></p>

<bitcoin-core><source-code>
Why was 'extern' used in the noui.h file?
jinsong ai
# Why was 'extern' used in the noui.h file?

(Asked by: username_0 on 2018-08-31)

When I review the Bitcoin Core source code, I see the `noui.h` as a header file, but the method `noui_connect` has been declared with the keyword `extern`. I think there is no need to do this.

`extern void noui_connect();`

**Tags:** bitcoin-core, source-code


---

## 1 answers

### Answer by username_1 on 2018-08-31. Score: 3 | Accepted answer

extern before function prototypes does not have any effect. If it were a variable, it’d be needed to specify that the variable was declared somewhere else.
void noui_connect();

void noui_connect() {/*something*/}

^^^The compiler can easily find which is the prototype and which is the implementation of the same function. However,
// main.h
int a;
// main.c
#include "main.h"
int a = 5;
// util.c
#include "main.h"

^^^The compiler might create two symbols. One in main.c, one in util.c. To prevent creation of another variable, the extern keyword is used to leave the variable to the linker, the final step at compiling.
On the contrary, the function prototypes, not the implementations are put in header files, which are always left to the linker. Because that's the way function prototypes are designed, they don't need extern.
If you see extern before function prototypes, that's pure coding style, probably to be consistent with other extern variables.

> **Comments:**
> **username_2**: Not just consistency, but also clarity. It explicitly signifies to the programmer "The function is not being defined here". Even though it is obvious to the compiler does not mean it must be obvious to developers.  

---

