digitalmars.D - C++ interface.
- monnoroch (12/12) Apr 01 2014 Could anyone explain, why D cannot interface C++ functions in
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (3/5) Apr 01 2014 However, the mangling itself is not standardized.
- monnoroch (2/3) Apr 01 2014 Yes, i know that, but since dmd already can decrypt the mangling
- John Colvin (3/8) Apr 01 2014 Is it prohibitively arduous just to emulate a variety of common
- Walter Bright (3/4) Apr 01 2014 That isn't the problem - dmd emits custom mangling for each platform.
- John Colvin (4/9) Apr 01 2014 uninstantiable struct? (as an aside, it'd be nice to have
- monnoroch (16/17) Apr 01 2014 Why don't just use dot? So, that:
- Walter Bright (2/5) Apr 01 2014 The D compiler has nowhere to search for nmr::initialize.
- monnoroch (4/5) Apr 01 2014 Oops, forgot, that it uses gcc to link...
- Asman01 (5/10) Apr 01 2014 Why do we don't use our own linker? better, what exactly do we
- monnoroch (7/8) Apr 01 2014 The whole point of a question was to ask for a feature, that
- Daniel Murphy (4/6) Apr 01 2014 Well, someone would need to add ELF support since it's currently OMF/COF...
- monnoroch (3/3) Apr 01 2014 Also you could demangling add instantiated templates. If they
- Jacob Carlborg (10/14) Apr 01 2014 with UDA's, of course :)
- monnoroch (7/8) Apr 01 2014 Truth is: right now, any way is better, than don't do that, since
- Mike Parker (5/13) Apr 01 2014 People who are concerned about cross-language compatibility
- monnoroch (7/11) Apr 02 2014 True. But i find myself with like 10+Gb of c++ sources, are you
- Mike Parker (8/19) Apr 02 2014 What I'm suggesting is that there are a lot of people with a lot of
- "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= (4/8) Apr 02 2014 I thought it was a stated goal of D to have C++ interoperability
- Daniel =?ISO-8859-2?B?S2964Ws=?= (5/14) Apr 02 2014 V Wed, 02 Apr 2014 10:57:15 +0000
- Daniel Murphy (4/9) Apr 03 2014 It does, on non-windows platforms, although C++ interoperability is clos...
- monnoroch (4/4) Apr 01 2014 I mean, it would be just super cool. At my work we have like
- Rene Zwanenburg (15/19) Apr 01 2014 If you know how your C++ compiler mangles functions inside
- Jacob Carlborg (5/24) Apr 01 2014 That's not currently possible. Have a look at this:
- Jacob Carlborg (5/14) Apr 01 2014 I'm pretty sure you can use extern (C++) then manually specify the
Could anyone explain, why D cannot interface C++ functions in namespaces like that: namespace A { struct S {}; struct T {}; S* get(T* v); } Because i just ddon't get it: namespaces are just a part of C++ name mangling, they are not something special. Support of this kind of functions would make it much easier to integrate D in existing C++ repos, which is the key to success (sadly, though).
Apr 01 2014
On 04/01/2014 10:32 AM, monnoroch wrote:namespaces are just a part of C++ name mangling, they are not something special.However, the mangling itself is not standardized. Ali
Apr 01 2014
However, the mangling itself is not standardized.Yes, i know that, but since dmd already can decrypt the mangling of overloaded functions, it could just do the same for namespaces.
Apr 01 2014
On Tuesday, 1 April 2014 at 17:38:08 UTC, Ali Çehreli wrote:On 04/01/2014 10:32 AM, monnoroch wrote:Is it prohibitively arduous just to emulate a variety of common compilers and control it with a compiler switch?namespaces are just a part of C++ name mangling, they are not something special.However, the mangling itself is not standardized. Ali
Apr 01 2014
On 4/1/2014 10:38 AM, Ali Çehreli wrote:However, the mangling itself is not standardized.That isn't the problem - dmd emits custom mangling for each platform. The problem is "how to specify C++ namespaces in D".
Apr 01 2014
On Tuesday, 1 April 2014 at 18:37:06 UTC, Walter Bright wrote:On 4/1/2014 10:38 AM, Ali Çehreli wrote:uninstantiable struct? (as an aside, it'd be nice to have disable init for making truly uninstantiable structs). Or just use modules, if that can be made to work.However, the mangling itself is not standardized.That isn't the problem - dmd emits custom mangling for each platform. The problem is "how to specify C++ namespaces in D".
Apr 01 2014
On Tuesday, 1 April 2014 at 18:37:06 UTC, Walter Bright wrote:The problem is "how to specify C++ namespaces in D".Why don't just use dot? So, that: extern(C++) { void nmr.initialize(int argc, const(char)*[] argv); } Would get converted to whatever void nmr::initialize(int, const(char)*[]) would became mangled in c++. If you do not want to hack parser into doing it, just nmr_initialize would be ok. So, if i write: extern(C++) { void nmr_initialize(int argc, const(char)*[] argv); } It would first try to search nmr_initialize itself, and if thre is no, it would try to find nmr::initialize. Recursevly y the number of ::-s.
Apr 01 2014
On 4/1/2014 12:29 PM, monnoroch wrote:It would first try to search nmr_initialize itself, and if thre is no, it would try to find nmr::initialize. Recursevly y the number of ::-s.The D compiler has nowhere to search for nmr::initialize.
Apr 01 2014
On Tuesday, 1 April 2014 at 19:51:25 UTC, Walter Bright wrote:The D compiler has nowhere to search for nmr::initialize.Oops, forgot, that it uses gcc to link... Then maby nmr__initialize would be ok? I mean, nobody uses two underscores in the code.
Apr 01 2014
On Tuesday, 1 April 2014 at 19:59:03 UTC, monnoroch wrote:On Tuesday, 1 April 2014 at 19:51:25 UTC, Walter Bright wrote:Why do we don't use our own linker? better, what exactly do we need to begin using the Daniel's linker instead of gcc's? I see this like a big deal but the guy didn't get much feedback from his announce.The D compiler has nowhere to search for nmr::initialize.Oops, forgot, that it uses gcc to link... Then maby nmr__initialize would be ok? I mean, nobody uses two underscores in the code.
Apr 01 2014
On Tuesday, 1 April 2014 at 20:26:28 UTC, Asman01 wrote:Why do we don't use our own linker?The whole point of a question was to ask for a feature, that would boost D usage in case of existing c++ codebase. I doubt that new linker will be ready and stable for both D and c/c++ object files any time soon. For instance, i have to link D object files with gcc so, i couldn't benefit from new linker anyway.
Apr 01 2014
"Asman01" wrote in message news:qltrgqselahxazgrqdxo forum.dlang.org...Why do we don't use our own linker? better, what exactly do we need to begin using the Daniel's linker instead of gcc's?Well, someone would need to add ELF support since it's currently OMF/COFF only. While a linker technically _could_ help here with some magic symbol rewriting, it's far from the most practical way to get namespaces working.
Apr 01 2014
Also you could demangling add instantiated templates. If they already exist in object files, not only in headers, why not link to them? It seems to me, that it is also just demangling problem.
Apr 01 2014
On 2014-04-01 20:37, Walter Bright wrote:On 4/1/2014 10:38 AM, Ali Çehreli wrote:with UDA's, of course :) namespace("foo::bar") { extern (C++): void foo (); void bar (); } -- /Jacob CarlborgHowever, the mangling itself is not standardized.That isn't the problem - dmd emits custom mangling for each platform. The problem is "how to specify C++ namespaces in D".
Apr 01 2014
On Tuesday, 1 April 2014 at 18:37:06 UTC, Walter Bright wrote:The problem is "how to specify C++ namespaces in D".Truth is: right now, any way is better, than don't do that, since it seems that the c++ linking problem stops alot of people to use D. C++ name mangling isn't standartized anyway, so whatever the solution will be, people will understand both syntax and possible lack of backward compaility.
Apr 01 2014
On Tuesday, 1 April 2014 at 19:38:11 UTC, monnoroch wrote:On Tuesday, 1 April 2014 at 18:37:06 UTC, Walter Bright wrote:People who are concerned about cross-language compatibility should be implementing C interfaces to their C++ libraries anyway. Yes, it's a nice, convenient feature to have, but ultimately there are more important things, IMO.The problem is "how to specify C++ namespaces in D".Truth is: right now, any way is better, than don't do that, since it seems that the c++ linking problem stops alot of people to use D. C++ name mangling isn't standartized anyway, so whatever the solution will be, people will understand both syntax and possible lack of backward compaility.
Apr 01 2014
On Wednesday, 2 April 2014 at 04:59:11 UTC, Mike Parker wrote:People who are concerned about cross-language compatibility should be implementing C interfaces to their C++ libraries anyway. Yes, it's a nice, convenient feature to have, but ultimately there are more important things, IMO.True. But i find myself with like 10+Gb of c++ sources, are you suggesting that i should write C wrapper for all that code to use D? Or maby you suggesting that i have to make all my (hundreds) collegs write C wrappers for all new code? I really just trying to start D community in company i work, and there is no way to do it without nice integration with old codebase.
Apr 02 2014
On 4/2/2014 7:30 PM, monnoroch wrote:On Wednesday, 2 April 2014 at 04:59:11 UTC, Mike Parker wrote:What I'm suggesting is that there are a lot of people with a lot of different priorities and still a lot of work to be done just to get the core language features where they need to be. D already has interop with C and that's been extremely important. While I think it would be fantastic to have fully-functional C++ interop so that one could just drop a D module into a project and take off, I wouldn't expect that to be a major priority at this time.People who are concerned about cross-language compatibility should be implementing C interfaces to their C++ libraries anyway. Yes, it's a nice, convenient feature to have, but ultimately there are more important things, IMO.True. But i find myself with like 10+Gb of c++ sources, are you suggesting that i should write C wrapper for all that code to use D? Or maby you suggesting that i have to make all my (hundreds) collegs write C wrappers for all new code? I really just trying to start D community in company i work, and there is no way to do it without nice integration with old codebase.
Apr 02 2014
On Wednesday, 2 April 2014 at 04:59:11 UTC, Mike Parker wrote:People who are concerned about cross-language compatibility should be implementing C interfaces to their C++ libraries anyway. Yes, it's a nice, convenient feature to have, but ultimately there are more important things, IMO.I thought it was a stated goal of D to have C++ interoperability for the same compiler suite? E.g. dmd/dmc++, g++/gdc, ldc/clang…
Apr 02 2014
V Wed, 02 Apr 2014 10:57:15 +0000 "Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang gmail.com>" puremagic.com napsáno:On Wednesday, 2 April 2014 at 04:59:11 UTC, Mike Parker wrote:This would be awesome. But it would be much better if DMD has interoperability with g++ and/or clang too.People who are concerned about cross-language compatibility should be implementing C interfaces to their C++ libraries anyway. Yes, it's a nice, convenient feature to have, but ultimately there are more important things, IMO.I thought it was a stated goal of D to have C++ interoperability for the same compiler suite? E.g. dmd/dmc++, g++/gdc, ldc/clang…
Apr 02 2014
"DanielKozák" wrote in message news:mailman.36.1396437697.19942.digitalmars-d puremagic.com...It does, on non-windows platforms, although C++ interoperability is closer to a nice-to-have than a 'stated goal'.I thought it was a stated goal of D to have C++ interoperability for the same compiler suite? E.g. dmd/dmc++, g++/gdc, ldc/clang…This would be awesome. But it would be much better if DMD has interoperability with g++ and/or clang too.
Apr 03 2014
I mean, it would be just super cool. At my work we have like gigabytes of c++ code, and almost all of it in namespaces, if i just could write simple extern(C++) declarations for them it would be so much easier to start working with D.
Apr 01 2014
On Tuesday, 1 April 2014 at 17:49:21 UTC, monnoroch wrote:I mean, it would be just super cool. At my work we have like gigabytes of c++ code, and almost all of it in namespaces, if i just could write simple extern(C++) declarations for them it would be so much easier to start working with D.If you know how your C++ compiler mangles functions inside namespaces, you should be able to hack something together using pragma mangle. I'm not sure how nice it can be, ideally a UDA (user defined attribute) should be enough, but I've never used them myself so I don't know if this is possible: Cpp("namespace") void foo(int x); or even: Cpp("namespace") { void foo(); void bar(); } where Cpp applies extern(C++) and pragma(mangle, "correctlymangledname"). Anyone knows if this can be done?
Apr 01 2014
On 2014-04-01 20:01, Rene Zwanenburg wrote:On Tuesday, 1 April 2014 at 17:49:21 UTC, monnoroch wrote:That's not currently possible. Have a look at this: http://wiki.dlang.org/DIP50#C.2B.2B_Namespaces_.28issue_7961.29 -- /Jacob CarlborgI mean, it would be just super cool. At my work we have like gigabytes of c++ code, and almost all of it in namespaces, if i just could write simple extern(C++) declarations for them it would be so much easier to start working with D.If you know how your C++ compiler mangles functions inside namespaces, you should be able to hack something together using pragma mangle. I'm not sure how nice it can be, ideally a UDA (user defined attribute) should be enough, but I've never used them myself so I don't know if this is possible: Cpp("namespace") void foo(int x); or even: Cpp("namespace") { void foo(); void bar(); } where Cpp applies extern(C++) and pragma(mangle, "correctlymangledname"). Anyone knows if this can be done?
Apr 01 2014
On 2014-04-01 19:32, monnoroch wrote:Could anyone explain, why D cannot interface C++ functions in namespaces like that: namespace A { struct S {}; struct T {}; S* get(T* v); } Because i just ddon't get it: namespaces are just a part of C++ name mangling, they are not something special.I'm pretty sure you can use extern (C++) then manually specify the mangling using pragma(mangle, "mangled_c++_name"). -- /Jacob Carlborg
Apr 01 2014