www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is the difference between extern(C++) extern(D)

reply lili <akozhao tencent.com> writes:
Hi Guys;
    In the dmd source code, has lot of extern (C++), Why need this 
and what is difference between extern(C++) extern(D), Thanks your 
answer.
Jun 19 2019
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, June 19, 2019 11:12:14 AM MDT lili via Digitalmars-d-learn 
wrote:
 Hi Guys;
     In the dmd source code, has lot of extern (C++), Why need this
 and what is difference between extern(C++) extern(D), Thanks your
 answer.
extern(C++) is for making the name mangling match C++, extern(C) would be the same for C (though in that case, it would mean no name mangling), and extern(D) is the same as not using extern at all; it's for the normal D name mangling. extern(C) and extern(C++) are either exposing symbols from D to those languages (e.g. if you're creating a library) or for exposing symbols from those languages to D (e.g. that's what core.stdc.* does with C's standard library so that it can be used from D). https://dlang.org/spec/interfaceToC.html https://dlang.org/spec/cpp_interface.html - Jonathan M Davis
Jun 19 2019