I know that extern "C" used to turn off the decoration of names, which is often used for exported functions.

And what does extern "C++" do?


The header file corecrt.h contains

 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // // C++ Secure Overload Generation Macros // //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #ifndef RC_INVOKED #if defined __cplusplus && _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES #define __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(_ReturnType, _FuncName, _DstType, _Dst) \ extern "C++" \ { \ template <size_t _Size> \ inline \ _ReturnType __CRTDECL _FuncName(_DstType (&_Dst)[_Size]) _CRT_SECURE_CPP_NOTHROW \ { \ return _FuncName(_Dst, _Size); \ } \ } 

The macro is further used in stdio.h :

 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0( char*, gets_s, char, _Buffer) 

to declare functions with a fixed-size array:

gets_s

Visual Studio 2015 Compiler

    1 answer 1

    To communicate with other programming languages, C ++ introduced a specification called the linkage specification .

    From C ++ standard (7.5 Linkage specifications)

    1 All language types, function names with external linkage, and variable names with external linkage have a language linkage. It is not possible to refer here. For example, it should be noted. β€”End note] This is a C ++ language linkage. If you are otherwise identical.

    The standard supports two literals used to communicate with other languages. it

     extern "C++" 

    and

     extern "C" 

    Other literals in this specification can be supported independently by compiler implementations.

    For example, names in the C ++ program can be used (for example, functions) from the Fortran programming language. In this case, these names may be preceded by a specification.

     extern "FORTRAN" 
    • Why specify extern "C++" if it goes by default? - Qwertiy ♦
    • @Qwertiy To distinguish between two names gets_s, one of which is declared as having "C" language binding, and the other as "C ++" having language binding. - Vlad from Moscow