IT lexicon › Programming › extern "C"

extern "C"

Programming På svenska → Updated: 2026-11-06

The C++ declaration that switches off name mangling and gives a function C linkage and calling convention.

A C++ compiler renames int f(int) to something like _Z1fi, while a C linker goes looking for f. The linkage specification arrived with type-safe linkage in Cfront 2.0 in 1989 and has wrapped nearly every C header on earth since: #ifdef __cplusplus followed by extern "C" {, so one file works from both languages.

The cost is that everything C++-specific vanishes from the symbol. Two extern "C" functions with the same name cannot be overloaded, and an exception thrown through a C frame has no defined behaviour. The syntax has spread well beyond C++: Rust writes extern "C" fn for the same thing, and plugin systems load functions with dlsym precisely because their names are predictable.

← Back to the lexicon