Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between declaration of function with extern and without it

Tags:

c++

There is such code:

#include <iostream>

extern void fun();

int main(){
    fun();
    return 0;
}

void fun(){ std::cout << "Hello" << std::endl; }

Is there some difference between declarations:

extern void fun();
void fun();

? Code above behaves the same with extern and without extern keyword.

like image 954
scdmb Avatar asked Dec 27 '22 12:12

scdmb


1 Answers

Function declarations do have external linkage by default, so adding the extern keyword to a function declaration makes no difference, it is redundant.

like image 100
Alok Save Avatar answered Feb 13 '23 04:02

Alok Save