Jump to page: 1 2 3
Thread overview
C++ interface.
Apr 01, 2014
monnoroch
Apr 01, 2014
Ali Çehreli
Apr 01, 2014
monnoroch
Apr 01, 2014
John Colvin
Apr 01, 2014
Walter Bright
Apr 01, 2014
John Colvin
Apr 01, 2014
monnoroch
Apr 01, 2014
Walter Bright
Apr 01, 2014
monnoroch
Apr 01, 2014
Asman01
Apr 01, 2014
monnoroch
Apr 02, 2014
Daniel Murphy
Apr 01, 2014
monnoroch
Apr 01, 2014
Jacob Carlborg
Apr 01, 2014
monnoroch
Apr 02, 2014
Mike Parker
Apr 02, 2014
monnoroch
Apr 02, 2014
Mike Parker
Apr 02, 2014
Daniel Kozák
Apr 03, 2014
Daniel Murphy
Apr 01, 2014
monnoroch
Apr 01, 2014
Rene Zwanenburg
Apr 01, 2014
Jacob Carlborg
Apr 01, 2014
Jacob Carlborg
April 01, 2014
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).
April 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

April 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.
April 01, 2014
On Tuesday, 1 April 2014 at 17:38:08 UTC, Ali Çehreli wrote:
> 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

Is it prohibitively arduous just to emulate a variety of common compilers and control it with a compiler switch?
April 01, 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.
April 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
April 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?
April 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".

April 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:
>> 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".

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.
April 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.
« First   ‹ Prev
1 2 3