www.digitalmars.com         C & C++   DMDScript  

D - interoperability with C++

reply "Ben Hinkle" <bhinkle4 juno.com> writes:
One thing that would be a huge plus for D compared to any other language
would be good C++ interoperability of some kind. Playing well with C is a
requirement for any serious language. My bet is playing well with C++ will
be just as important in the future, if not already.

Managed Extensions to C++ (though I don't know any details about it). D
doesn't seem to have anything planned here or a story to tell users. Any
time C++ code wants to talk to D code or vice-versa you have to go through
C.

I noticed the dmd source code has a linkage enum entry for C++ (in addition
to the C, Pascal, D and Windows options already implemented). What are the
major obstacles to implementing it?

-Ben
Feb 11 2004
parent reply "Walter" <walter digitalmars.com> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c0dugh$enh$1 digitaldaemon.com...
 One thing that would be a huge plus for D compared to any other language
 would be good C++ interoperability of some kind. Playing well with C is a
 requirement for any serious language. My bet is playing well with C++ will
 be just as important in the future, if not already.

 Managed Extensions to C++ (though I don't know any details about it). D
 doesn't seem to have anything planned here or a story to tell users. Any
 time C++ code wants to talk to D code or vice-versa you have to go through
 C.

 I noticed the dmd source code has a linkage enum entry for C++ (in
addition
 to the C, Pascal, D and Windows options already implemented). What are the
 major obstacles to implementing it?
The problem is the layout of the vtbl[]. To get that right, you have to build part of a C++ compiler.
Feb 11 2004
next sibling parent reply Bastiaan Veelo <Bastiaan.N.Veelo ntnu.no> writes:
Walter wrote:
 "Ben Hinkle" <bhinkle4 juno.com> wrote in message
 news:c0dugh$enh$1 digitaldaemon.com...
 
One thing that would be a huge plus for D compared to any other language
would be good C++ interoperability of some kind. Playing well with C is a
requirement for any serious language. My bet is playing well with C++ will
be just as important in the future, if not already.

Managed Extensions to C++ (though I don't know any details about it). D
doesn't seem to have anything planned here or a story to tell users. Any
time C++ code wants to talk to D code or vice-versa you have to go through
C.

I noticed the dmd source code has a linkage enum entry for C++ (in
addition
to the C, Pascal, D and Windows options already implemented). What are the
major obstacles to implementing it?
The problem is the layout of the vtbl[]. To get that right, you have to build part of a C++ compiler.
If I understand this right, it _can_ be done, but implementing C++ interoperability would to a large extent undo the advantages of the D design for clean compiler code, and the added complexity would not be in proportion to what is needed to compile plain D. As much as it would be a pain for all of you putting so much effort in getting rid of C++ badness, would not it be doable to have two flavors of D compilers? One that does clean D and takes full advantage of its design, and an other that provides C++ interoperability, however cludgy? You would use the beautiful pure D compiler whenever possible, and the bulky ugly one when you need interoperability with C++. The D.gnu newsgroup is showing promising results recently, and since GCC already compiles C++, would it be possible to use the vtbl[] stuff that is already there? Also DM has a C++ compiler, which I hope means that relevant parts can be glued into its D compiler...? Not that this would be trivial, but probably not as bad as having to build part of a C++ compiler (from scratch) either. I am not in the same leage as most of you, and I have great respect for the work being done here. But I had to mention this --- I hope it makes sence :-) Bastiaan.
Feb 12 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
I vote no

"Bastiaan Veelo" <Bastiaan.N.Veelo ntnu.no> wrote in message
news:c0fija$35n$1 digitaldaemon.com...
 Walter wrote:
 "Ben Hinkle" <bhinkle4 juno.com> wrote in message
 news:c0dugh$enh$1 digitaldaemon.com...

One thing that would be a huge plus for D compared to any other language
would be good C++ interoperability of some kind. Playing well with C is
a
requirement for any serious language. My bet is playing well with C++
will
be just as important in the future, if not already.

Managed Extensions to C++ (though I don't know any details about it). D
doesn't seem to have anything planned here or a story to tell users. Any
time C++ code wants to talk to D code or vice-versa you have to go
through
C.

I noticed the dmd source code has a linkage enum entry for C++ (in
addition
to the C, Pascal, D and Windows options already implemented). What are
the
major obstacles to implementing it?
The problem is the layout of the vtbl[]. To get that right, you have to build part of a C++ compiler.
If I understand this right, it _can_ be done, but implementing C++ interoperability would to a large extent undo the advantages of the D design for clean compiler code, and the added complexity would not be in proportion to what is needed to compile plain D. As much as it would be a pain for all of you putting so much effort in getting rid of C++ badness, would not it be doable to have two flavors of D compilers? One that does clean D and takes full advantage of its design, and an other that provides C++ interoperability, however cludgy? You would use the beautiful pure D compiler whenever possible, and the bulky ugly one when you need interoperability with C++. The D.gnu newsgroup is showing promising results recently, and since GCC already compiles C++, would it be possible to use the vtbl[] stuff that is already there? Also DM has a C++ compiler, which I hope means that relevant parts can be glued into its D compiler...? Not that this would be trivial, but probably not as bad as having to build part of a C++ compiler (from scratch) either. I am not in the same leage as most of you, and I have great respect for the work being done here. But I had to mention this --- I hope it makes sence :-) Bastiaan.
Feb 12 2004
prev sibling next sibling parent reply =?iso-8859-1?Q?=22Robert_M._M=FCnch=22?= <robert.muench robertmuench.de> writes:
On Wed, 11 Feb 2004 20:18:02 -0800, Walter <walter digitalmars.com> wrote:

 The problem is the layout of the vtbl[]. To get that right, you have to
 build part of a C++ compiler.
Well, you have a nice C++ compiler at hand. I wouldn't mind if I only can link it with DMC++ compiled code. At least this would makes bootstrapping D projects much simpler. Over time D libraries will develop and replace more and more C++ libaries. I would add DMC++ compatibility. -- Robert M. Münch Management & IT Freelancer http://www.robertmuench.de
Feb 12 2004
parent Sean Kelly <sean ffwd.cx> writes:
Robert M. Münch wrote:

 On Wed, 11 Feb 2004 20:18:02 -0800, Walter <walter digitalmars.com> wrote:
 
 The problem is the layout of the vtbl[]. To get that right, you have to
 build part of a C++ compiler.
Well, you have a nice C++ compiler at hand. I wouldn't mind if I only can link it with DMC++ compiled code. At least this would makes bootstrapping D projects much simpler. Over time D libraries will develop and replace more and more C++ libaries. I would add DMC++ compatibility.
I think it would add too much complexity to the D compiler implementation. I vote no. Sean
Feb 12 2004
prev sibling next sibling parent "Ben Hinkle" <bhinkle4 juno.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:c0ev8k$24q3$1 digitaldaemon.com...
|
| "Ben Hinkle" <bhinkle4 juno.com> wrote in message
| news:c0dugh$enh$1 digitaldaemon.com...
| > One thing that would be a huge plus for D compared to any other language
| > would be good C++ interoperability of some kind. Playing well with C is a
| > requirement for any serious language. My bet is playing well with C++ will
| > be just as important in the future, if not already.

| > Managed Extensions to C++ (though I don't know any details about it). D
| > doesn't seem to have anything planned here or a story to tell users. Any
| > time C++ code wants to talk to D code or vice-versa you have to go through
| > C.
| >
| > I noticed the dmd source code has a linkage enum entry for C++ (in
| addition
| > to the C, Pascal, D and Windows options already implemented). What are the
| > major obstacles to implementing it?
|
| The problem is the layout of the vtbl[]. To get that right, you have to
| build part of a C++ compiler.
|

Would it be possible to have an API to use D objects from C++ (instead of the
other way around)? I notice the
D spec describes the object layout and vtbl, so that is a start. Some way to
call constructors would probably
be needed.

Also it occurred to me that COM provides a basic story on win32. For other
platforms maybe CORBA could help
(though that would probably bring a lot of infrastructure). It wouldn't be as
nice as seemlessly
interoperating but it is a step beyond "extern (C)".

-Ben
Feb 12 2004
prev sibling parent "Angelo Moscati" <a.moscati newmail.net> writes:
I don't have a good knowledge about compilation, but I thought if it is
possible
to write a tool that automatically generate from a c++ library a interface
for use it.

I'm sorry for my english, what i mean is that the tool write a D module that
define
a class.
This class has all the public methos of the original class in the c++
library.
When someone calls a method from this class, it will do all the necessary
operations
(I don't know what) and after it executes the original method ( I assume we
can know where
the method is from the vtbl).
Please tell me if something lime this is possible.

"Walter" <walter digitalmars.com> wrote in message
news:c0ev8k$24q3$1 digitaldaemon.com...
 "Ben Hinkle" <bhinkle4 juno.com> wrote in message
 news:c0dugh$enh$1 digitaldaemon.com...
 One thing that would be a huge plus for D compared to any other language
 would be good C++ interoperability of some kind. Playing well with C is
a
 requirement for any serious language. My bet is playing well with C++
will
 be just as important in the future, if not already.

 Managed Extensions to C++ (though I don't know any details about it). D
 doesn't seem to have anything planned here or a story to tell users. Any
 time C++ code wants to talk to D code or vice-versa you have to go
through
 C.

 I noticed the dmd source code has a linkage enum entry for C++ (in
addition
 to the C, Pascal, D and Windows options already implemented). What are
the
 major obstacles to implementing it?
The problem is the layout of the vtbl[]. To get that right, you have to build part of a C++ compiler.
Feb 14 2004