Why would you use 'extern “C++”'?

前端 未结 10 1454
失恋的感觉
失恋的感觉 2020-12-12 17:37

In this article the keyword extern can be followed by \"C\" or \"C++\". Why would you use \'extern \"C++\"\'? Is it practical?

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 18:35

    extern "C" is used to say that a C++ function should have C linkage. What this means is implementation dependant, but normally it turns off C++ name-mangling (and so overloading and strict type checking). You use it when you have a C++ function you want to be called from C code:

    extern "C" void Foo();   // can be called easily from C
    

    As for extern "C++", I've never seen it in real code, though the C++ Standard allows it. I guess it is a no-op.

提交回复
热议问题