www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - C++ Binding / extern(C++)

reply Dan <murpsoft hotmail.com> writes:
I was just discussing how difficult it would be for someone to write C++
bindings to a project on the dsource forums, and remembered how I wanted to use
Ogre with D and wished Sinbad was done... and how DirectFB is done in C++...

Has anyone figured out how to bind D to C++ on any include/importable level?
(source, AST, OBJ files, extern'ing to the *.h files)

If they have, maybe we can set up a project to automatically bind C++ projects
in, and Walter might add it to his linker?

For example, matching scrambled names by scrambling  a copy of the D ones,
matching it, binding it?

Or perhaps if Walter allowed extern(C++) by matching the identifiers in the
AST's and passed the extern(C++) segment to the digital mars C++ compiler with
the shared identifiers?

Just my thoughts...
Mar 28 2007
parent reply Gregor Richards <Richards codu.org> writes:
Dan wrote:
 I was just discussing how difficult it would be for someone to write C++
bindings to a project on the dsource forums, and remembered how I wanted to use
Ogre with D and wished Sinbad was done... and how DirectFB is done in C++...
 
 Has anyone figured out how to bind D to C++ on any include/importable level?
(source, AST, OBJ files, extern'ing to the *.h files)
 
 If they have, maybe we can set up a project to automatically bind C++ projects
in, and Walter might add it to his linker?
 
 For example, matching scrambled names by scrambling  a copy of the D ones,
matching it, binding it?
 
 Or perhaps if Walter allowed extern(C++) by matching the identifiers in the
AST's and passed the extern(C++) segment to the digital mars C++ compiler with
the shared identifiers?
 
 Just my thoughts...

There already is a project to automatically bind C++ to D, it's just not particularly complete or accurate. http://www.dsource.org/projects/bcd/ The method is simple: Generate a C binding to the C++, then generate a D binding to the C. - Gregor Richards PS: extern(C++) is a terrible idea. It wouldn't be cross-compatible.
Mar 28 2007
parent reply Don Clugston <dac nospam.com.au> writes:
Gregor Richards wrote:
 PS: extern(C++) is a terrible idea. It wouldn't be cross-compatible.

incompatible with C++.
Mar 29 2007
parent reply =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
Don Clugston kirjoitti:
 Gregor Richards wrote:
 PS: extern(C++) is a terrible idea. It wouldn't be cross-compatible.

incompatible with C++.

Yeah, even this (http://www.mozilla.org/hacking/portable-cpp.html) tells a lot. I don't know, whether I should laugh or cry.
Mar 29 2007
next sibling parent reply Don Clugston <dac nospam.com.au> writes:
Jari-Matti Mäkelä wrote:
 Don Clugston kirjoitti:
 Gregor Richards wrote:
 PS: extern(C++) is a terrible idea. It wouldn't be cross-compatible.

incompatible with C++.

Yeah, even this (http://www.mozilla.org/hacking/portable-cpp.html) tells a lot. I don't know, whether I should laugh or cry.

Great link. It was as a result of writing this... http://www.codeproject.com/cpp/FastDelegate.asp ...that I switched to D. It seems that even the compiler writers don't know this stuff (several emailed me about it). C++ portability is a complete fiasco.
Mar 29 2007
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Don Clugston wrote:
 It was as a result of writing this...
 
 http://www.codeproject.com/cpp/FastDelegate.asp

Wait, *you're* the guy that wrote that? Great article. Even though I never actually used the technique it presents I learned a lot from it. Also, like Walter, you look nothing like I imagined :P.
Mar 29 2007
next sibling parent Johan Granberg <lijat.meREM OVEgmail.com> writes:
Frits van Bommel wrote:

 Don Clugston wrote:
 It was as a result of writing this...
 
 http://www.codeproject.com/cpp/FastDelegate.asp

Wait, *you're* the guy that wrote that? Great article. Even though I never actually used the technique it presents I learned a lot from it. Also, like Walter, you look nothing like I imagined :P.

I agree with all above, great article :P. Ironically I found that article when trying to learn how to use pointers to member functions and it helped me learn how to use them adequately. :D
Mar 29 2007
prev sibling parent reply Don Clugston <dac nospam.com.au> writes:
Frits van Bommel wrote:
 Don Clugston wrote:
 It was as a result of writing this...

 http://www.codeproject.com/cpp/FastDelegate.asp

Wait, *you're* the guy that wrote that? Great article. Even though I never actually used the technique it presents I learned a lot from it.

Thanks! I learnt a lot from it too...
 Also, like Walter, you look nothing like I imagined :P.

I'm intrigued. What did you imagine? Something a bit more exotic?
Mar 29 2007
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Don Clugston wrote:
 Frits van Bommel wrote:
 Don Clugston wrote:
 It was as a result of writing this...

 http://www.codeproject.com/cpp/FastDelegate.asp

Wait, *you're* the guy that wrote that? Great article. Even though I never actually used the technique it presents I learned a lot from it.

Thanks! I learnt a lot from it too...
 Also, like Walter, you look nothing like I imagined :P.

I'm intrigued. What did you imagine? Something a bit more exotic?

For some reason I expected Jim Blinn's twin: http://vis.computer.org/Vis2003/session/capstone.html --bb
Mar 29 2007
next sibling parent kris <foo bar.com> writes:
Bill Baxter wrote:
 Don Clugston wrote:
 
 Frits van Bommel wrote:

 Don Clugston wrote:

 It was as a result of writing this...

 http://www.codeproject.com/cpp/FastDelegate.asp

Wait, *you're* the guy that wrote that? Great article. Even though I never actually used the technique it presents I learned a lot from it.

Thanks! I learnt a lot from it too...
 Also, like Walter, you look nothing like I imagined :P.

I'm intrigued. What did you imagine? Something a bit more exotic?

For some reason I expected Jim Blinn's twin: http://vis.computer.org/Vis2003/session/capstone.html --bb

lol That FastDelegate article is really a great one, and I agree about the JamesBlinn notion :-)
Mar 29 2007
prev sibling parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Bill Baxter wrote:
 Don Clugston wrote:
 Frits van Bommel wrote:
 Don Clugston wrote:
 It was as a result of writing this...

 http://www.codeproject.com/cpp/FastDelegate.asp

Wait, *you're* the guy that wrote that? Great article. Even though I never actually used the technique it presents I learned a lot from it.

Thanks! I learnt a lot from it too...
 Also, like Walter, you look nothing like I imagined :P.

I'm intrigued. What did you imagine? Something a bit more exotic?

For some reason I expected Jim Blinn's twin: http://vis.computer.org/Vis2003/session/capstone.html

Yeah, something like that. Except with less hair below his face and more above. And perhaps a bit younger.
Mar 30 2007
parent Don Clugston <dac nospam.com.au> writes:
Frits van Bommel wrote:
 Bill Baxter wrote:
 Don Clugston wrote:
 Frits van Bommel wrote:
 Don Clugston wrote:
 It was as a result of writing this...

 http://www.codeproject.com/cpp/FastDelegate.asp

Wait, *you're* the guy that wrote that? Great article. Even though I never actually used the technique it presents I learned a lot from it.

Thanks! I learnt a lot from it too...
 Also, like Walter, you look nothing like I imagined :P.

I'm intrigued. What did you imagine? Something a bit more exotic?

For some reason I expected Jim Blinn's twin: http://vis.computer.org/Vis2003/session/capstone.html

Yeah, something like that. Except with less hair below his face and more above. And perhaps a bit younger.

Aarghh. The mystique is shattered. Nobody will take me seriously now.
Mar 30 2007
prev sibling next sibling parent reply "David B. Held" <dheld codelogicconsulting.com> writes:
Jari-Matti Mäkelä wrote:
 Don Clugston kirjoitti:
 Gregor Richards wrote:
 PS: extern(C++) is a terrible idea. It wouldn't be cross-compatible.

incompatible with C++.

Yeah, even this (http://www.mozilla.org/hacking/portable-cpp.html) tells a lot. I don't know, whether I should laugh or cry.

That's a 9 year old document last updated 6 years ago. C++ has come a ways since then, but I'm sure there would still be plenty to leave on the list. Dave
Mar 29 2007
parent =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
David B. Held wrote:
 Jari-Matti Mäkelä wrote:
 Don Clugston kirjoitti:
 Gregor Richards wrote:
 PS: extern(C++) is a terrible idea. It wouldn't be cross-compatible.

incompatible with C++.

Yeah, even this (http://www.mozilla.org/hacking/portable-cpp.html) tells a lot. I don't know, whether I should laugh or cry.

That's a 9 year old document last updated 6 years ago. C++ has come a ways since then, but I'm sure there would still be plenty to leave on the list.

Ah, yes - didn't notice that. I just saw "Last modified January 22, 2007" on the bottom of the page. But wait.. they have actually updated it after 2001. I'm not sure how true that is anymore, but it's still interesting to see a page like this.
Mar 29 2007
prev sibling parent James Dennett <jdennett acm.org> writes:
Jari-Matti Mäkelä wrote:
 Don Clugston kirjoitti:
 Gregor Richards wrote:
 PS: extern(C++) is a terrible idea. It wouldn't be cross-compatible.

incompatible with C++.


Just as C compilers are not always ABI-compatible. It's just that ABIs for C are more standard than for C++. There have been, for example, good quality C compilers that used name mangling to achieve type-safe linkage.
 Yeah, even this (http://www.mozilla.org/hacking/portable-cpp.html) tells
 a lot. I don't know, whether I should laugh or cry.

I cry; most of what it says doesn't apply to compilers from about the last decade. This is what happens when languages are hugely successful (in terms of installed base) -- they gain legacy burdens. If D does things well, you don't need to spread FUD about other languages. By all means compare, but naive bashing of other languages doesn't make the D community look healthy. -- James
Mar 29 2007