What is the difference between extern(C++) extern(D)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Jun 19 18:29:06 UTC 2019


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





More information about the Digitalmars-d-learn mailing list