Home

Extern

Extern is a programming term used to describe external linkage or declarations that reference symbols defined outside the current scope or translation unit. It signals that a symbol, such as a variable or function, is provided elsewhere, typically in another file or a library.

In C and C++, extern is a storage-class specifier that declares a variable or function without defining

Other languages use extern to reference foreign or native symbols as well. In Rust, extern is used

Etymologically, extern derives from Latin exter, external. It is not itself a storage directive; rather, it modifies

it,
indicating
external
linkage.
For
example,
extern
int
count;
declares
that
count
is
defined
in
another
translation
unit;
a
separate
definition
such
as
int
count
=
0;
in
another
file
provides
the
symbol.
Functions
are
extern
by
default;
extern
is
often
used
in
headers
to
declare
functions
or
global
variables.
Static,
by
contrast,
gives
internal
linkage.
C++
adds
extern
"C"
to
specify
C
linkage,
which
disables
name
mangling
to
improve
compatibility
with
C
code.
in
foreign-function
interface
(FFI)
blocks
to
declare
external
functions,
often
with
a
specific
ABI,
for
example
extern
"C"
{
fn
printf(...);
}.
In
C#
and
the
.NET
environment,
extern
appears
in
declarations
for
methods
implemented
in
unmanaged
code,
typically
together
with
DllImport
attributes
to
import
functions
from
native
libraries.
These
uses
share
the
common
goal
of
exposing
symbols
outside
the
current
language
or
module
boundary.
declarations
to
indicate
external
linkage
or
an
external
implementation.
Correct
use
helps
manage
cross-module
relationships
and
library
interfaces,
while
misuse
can
lead
to
unresolved
symbols
or
linkage
errors.