extern(C++, ns)

Anon via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 20 16:51:34 PST 2016


What would you all say to the following proposal (and should I 
make a DIP?)


1. deprecate pragma(mangle)
2. deprecate extern(C++, ns)
3. deprecate @selector()
4. Introduce a better, more general extern() as follows:

extern ( <LanguageIdent> [, <String> ] )

Which would *only* influence mangling and calling conventions. 
Blocks would concatenate their <String>s, with the default value 
for a symbol being its identifier. Whatever the concatenated 
string is then gets run through a language-specific mangler with 
knowledge of the type info. It would be an error for nesting 
blocks to change language. The content of the string would depend 
on the language in question. This would be also extendable beyond 
C, C++, D, and Objective-C to other languages if so desired 
(Rust, Go, C#, etc.) while keeping a uniform syntax and behavior 
regardless of the language being bound.

Some examples:

extern(C) int foo(); // Mangled as "foo"

extern(C, "body") int body_(); // "body"

extern(C++) int foo(); // cppMangleOf("foo")

extern(C++, "body") int body_(); // cppMangleOf("body")

extern(D) int foo(); // "_D3fooFZi" -no module

extern(D, "body") int body_; // "_D4bodyFZi" -no module

extern(C++, "ns::foo") int foo(); // cppMangleOf("ns::foo")

extern(C++, "ns::")
{
     int foo(); // cppMangleOf("ns::foo")

     extern(C++, "body") int body_(); // cppMangleOf("ns::body")

     // I'm unsure of the next two. Both need to be inside an
     // extern(<Lang>) block and would infer the <LanguageIdent>
     // extern("with") int with_(); // cppMangleOf("ns::with")
     // extern(auto, "with") int with_(); // 
cppMangleOf("ns::with")
}

extern(C, "SDL_")
{
     void init(); // "SDL_init"
}

extern(D, "std.ascii.")
{
     // std.ascii.isAlphaNum.mangleof
     bool isAlphaNum(dchar) pure nothrow @nogc @safe bool;
}


More information about the Digitalmars-d mailing list