How does extern "C" work in C++?

This question already has an answer here:

  • What is the effect of extern “C” in C++? 12 answers

  • It's probably not like that, but more like:

    #ifdef __cplusplus 
    extern "C" {
    #endif
    
    //some includes or declarations
    
    #ifdef __cplusplus 
    }
    #endif
    

    It tells the compiler to use C name mangling for whatever is declared inside the directives.

    The way you have it now:

    #ifdef __cplusplus 
    extern "C" {} 
    #endif
    

    is just dead code.


    It is used to inform the compiler to disable C++ name mangling for the functions defined within the braces. http://en.wikipedia.org/wiki/Name_mangling


    Extern "C" - 通知编译器,指出的函数是用C风格编译的。

    链接地址: http://www.djcxy.com/p/40486.html

    上一篇: 外部“C”函数内部使用C ++类

    下一篇: extern“C”如何在C ++中工作?