What does the extern keyword mean?

What does the extern keyword mean? I saw this before declaring a function, for example

 extern void DoFoo ... 
+52
c objective-c extern
May 02 '10 at 15:37
source share
3 answers

extern gives an external link. This means that an object or function is accessible through this name from other translation units in the program. For functions, this is the default binding anyway, so its use (in this context) is usually redundant.

+39
May 02 '10 at
source share

The extern keyword declares a variable or function and indicates that it has an external binding (its name is visible from files other than those in which it is defined). When a variable is changed, extern indicates that the variable has a static duration (it is allocated when the program starts and freed when the program ends). A variable or function can be defined in another source file or later in the same file. Declarations of variables and functions in the file area are external by default.

You can find a more complete description here .

+39
May 2 '10 at 3:38 PM
source share

For beginners,

I was initially confused to learn that "the extern keyword declares a variable or function and indicates that it has an external binding " from @Romain Hippeau.

Now I realized that we can share our variables with other classes using the extern keyword.

For example: Notification.h

enter image description here

Notification.m

enter image description here

Without the extern keyword The following error will be generated for the notification constant. enter image description here

+2
Sep 06 '17 at 15:06
source share



All Articles