Language linkage

Provides for linkage between program units written in different programming languages.

# Notes

Language specifications can only appear in namespace scope.

The braces of the language specification do not establish a scope.

When language specifications nest, the innermost specification is the one that is in effect.

A declaration directly contained in a language linkage specification is treated as if it contains the extern specifier for the purpose of determining the linkage of the declared name and whether it is a definition.

extern “C” makes it possible to include header files containing declarations of C library functions in a C++ program, but if the same header file is shared with a C program, extern “C” (which is not allowed in C) must be hidden with an appropriate #ifdef, typically __cplusplus:

The only modern compiler that differentiates function types with “C” and “C++” language linkages is Oracle Studio, others do not permit overloads that are only different in language linkage, including the overload sets required by the C++ standard (std::qsort, std::bsearch, std::signal, std::atexit, and std::at_quick_exit): GCC bug 2316, Clang bug 6277, CWG issue 1555.

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 4C++98names with internal linkage can have language linkageslimited to names with external linkage
CWG 341C++98a function with “C” language linkage canhave the same name as a global variablethe program is ill-formed in this case(no diagnostic required if theyappear in different translation units)
CWG 564C++98the program was ill-formed if two declarationsonly differ in language linkage specifications(i.e. different string literals following ’extern')the actual language linkages given bythe declarations are compared instead
CWG 2460C++20friend functions with a trailing requires clauseand “C” language linkage had conflict behaviors“C” language linkageis ignored in this case
CWG 2483C++98the linkage of the types of static member functionsappear in “C” language blocks was “C++”the linkage is “C”