Should functions be made "extern" in header files?

bodacydo picture bodacydo · Jul 29, 2010 · Viewed 38.9k times · Source

Should functions be made extern in header files? Or are they extern by default?

For example, should I write this:

// birthdays.h
struct person find_birthday(const char* name);

or this:

// birthdays.h
extern struct person find_birthday(const char* name);

Answer

Matthew Flaschen picture Matthew Flaschen · Jul 29, 2010

From The C Book:

If a declaration contains the extern storage class specifier, or is the declaration of a function with no storage class specifier (or both), then:

  • If there is already a visible declaration of that identifier with file scope, the resulting linkage is the same as that of the visible declaration;
  • otherwise the result is external linkage.

So if this is the only time it's declared in the translation unit, it will have external linkage.