Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of the extern keyword

Tags:

c

gcc

extern

c99

When I declare function prototypes in my header-files, I can reach those everywhere in my program, even though I never use the 'extern' keyword. Are they only important for static libraries, or when do I need it?

like image 278
Maestro Avatar asked Dec 20 '25 09:12

Maestro


2 Answers

Functions are extern by default. The extern keyword is only useful for variables.

like image 86
Oliver Charlesworth Avatar answered Dec 23 '25 03:12

Oliver Charlesworth


extern is default storage class specifier in C.

Explicitly specify it on variables

extern int i;

if it can be shared between modules. Then

int i;

in other module will not violate ODR.

For functions yes, pretty useless.

like image 35
Konstantin Vladimirov Avatar answered Dec 23 '25 01:12

Konstantin Vladimirov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!