0Pricing
C Academy · Lesson

extern and Linkage

Share symbols across files.

What Is Linkage?

Linkage describes whether a name can be shared between different source files.

A name with external linkage refers to the same entity across the whole program. A name with internal linkage is private to its own file. Understanding linkage is key to multi-file programs.

Sharing a Variable

Suppose two files need access to one global counter. You cannot simply define it in both files; that creates two separate variables and a duplicate-symbol link error.

Instead, you define it once and declare it everywhere else with extern.

/* config.c */
int g_count = 0;   /* the one definition */

All lessons in this course

  1. Header and Source Files
  2. Include Guards
  3. extern and Linkage
  4. Compiling Multiple Files
← Back to C Academy