April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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. |
April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rene Zwanenburg | On 2014-04-01 20:01, Rene Zwanenburg wrote: > 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? That's not currently possible. Have a look at this: http://wiki.dlang.org/DIP50#C.2B.2B_Namespaces_.28issue_7961.29 -- /Jacob Carlborg |
April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2014-04-01 20:37, Walter Bright wrote: > 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". with UDA's, of course :) @namespace("foo::bar") { extern (C++): void foo (); void bar (); } -- /Jacob Carlborg |
April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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.
|
April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to monnoroch | 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.
|
April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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.
|
April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to monnoroch | 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:
>> 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.
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.
|
April 01, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Asman01 | 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.
|
April 02, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Asman01 | "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. |
April 02, 2014 Re: C++ interface. | ||||
---|---|---|---|---|
| ||||
Posted in reply to monnoroch | 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:
>> 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.
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.
|
Copyright © 1999-2021 by the D Language Foundation