www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - d and c++

reply "Carlos Santander B." <carlos8294 msn.com> writes:
g++ seems to do a different name mangling than dmc, so this only works on
windows.

[file: test1.cpp]
#include <stdio.h>
void foo() { printf("Hi from C++\n"); }

[file: test2.d]
extern (C++) void foo();
void main() { foo(); }

 dmc -c test1.cpp
 dmd test2.d test1.obj
I guess it's good to have a shared backend. ----------------------- Carlos Santander Bernal
May 02 2004
parent reply Robert Jones <robertjones21 HotPOP.com> writes:
Carlos Santander B. wrote:
 g++ seems to do a different name mangling than dmc, so this only works on
 windows.
 
 [file: test1.cpp]
 #include <stdio.h>
 void foo() { printf("Hi from C++\n"); }
 
 [file: test2.d]
 extern (C++) void foo();
 void main() { foo(); }
 
 
dmc -c test1.cpp
dmd test2.d test1.obj
I guess it's good to have a shared backend. ----------------------- Carlos Santander Bernal
So there is some link compatibility with C++ on windows. Wonder if Walter is aware of this. I rewrote test1.cpp to use iostream and it still worked. I will continue to play around with this undocumented feature. Since gdc uses the same backend as g++, perhaps it can be done on Unix as well. If that works and once I've discovered how much of C++ I can link my D projects with, I go back to that FOX toolkit port I shelved. Being able to link against C++ object should make it easier, rather than rewriting the whole dang thing in D(the reason it's been shelved). -- Robert Jones robertjones21 HotPOP.com
Jul 13 2004
parent reply "David Barrett" <dbarrett quinthar.com> writes:
"Robert Jones" <robertjones21 HotPOP.com> wrote in message
news:cd0vg3$ik4$1 digitaldaemon.com...
 So there is some link compatibility with C++ on windows. Wonder if
 Walter is aware of this. I rewrote test1.cpp to use iostream and it
 still worked. I will continue to play around with this undocumented
feature. This is just C++ functions, not C++ objects/methods, right? -david
Jul 13 2004
parent reply Robert Jones <robertjones21 HotPOP.com> writes:
David Barrett wrote:
 "Robert Jones" <robertjones21 HotPOP.com> wrote in message
 news:cd0vg3$ik4$1 digitaldaemon.com...
 
So there is some link compatibility with C++ on windows. Wonder if
Walter is aware of this. I rewrote test1.cpp to use iostream and it
still worked. I will continue to play around with this undocumented
feature. This is just C++ functions, not C++ objects/methods, right? -david
That is what I intend to find out.
Jul 13 2004
parent reply Thomas Kuehne <eisvogel users.sourceforge.net> writes:
 
 This is just C++ functions, not C++ objects/methods, right?
 
As far as I can say C++ struct and functions work, but as soon as there is any class around - even if it's not accessed - thing screw up. system: linux / gcc 3.4. Thoas
Jul 13 2004
parent reply Robert Jones <robertjones21 HotPOP.com> writes:
Thomas Kuehne wrote:

This is just C++ functions, not C++ objects/methods, right?
As far as I can say C++ struct and functions work, but as soon as there is any class around - even if it's not accessed - thing screw up. system: linux / gcc 3.4.
Did you use gdc/gcc to run your test?
 Thoas
Jul 13 2004
parent Thomas Kuehne <eisvogel users.sourceforge.net> writes:
Robert Jones wrote:

This is just C++ functions, not C++ objects/methods, right?
As far as I can say C++ struct and functions work, but as soon as there is any class around - even if it's not accessed - thing screw up. system: linux / gcc 3.4.
Did you use gdc/gcc to run your test?
No, dmd 0.95 a primitive example is: (note that only "add" has C linkage but "multi" C++) ----a.cpp---- typedef struct MyStruct{ int i; char c; }; void multi(MyStruct* arg){ arg->i = arg->i * 3; } extern "C" { void add(MyStruct* arg); } void add(MyStruct* arg){ arg->c = arg->c+1; multi(arg); } ----b.d---- extern(C){ struct MyStruct{ int i; char c; } void add(MyStruct* ); } int main(){ MyStruct m; m.i=1; m.c='A'; printf("%i %c\n", m.i, m.c); add(&m); printf("%i %c\n", m.i, m.c); return 0; }
Jul 13 2004