digitalmars.D - d and c++
- Carlos Santander B. (11/13) May 02 2004 g++ seems to do a different name mangling than dmc, so this only works o...
- Robert Jones (13/36) Jul 13 2004 So there is some link compatibility with C++ on windows. Wonder if
- David Barrett (5/8) Jul 13 2004 feature.
- Robert Jones (2/16) Jul 13 2004 That is what I intend to find out.
- Thomas Kuehne (4/7) Jul 13 2004 As far as I can say C++ struct and functions work, but as soon as there ...
- Robert Jones (2/11) Jul 13 2004
- Thomas Kuehne (33/41) Jul 13 2004 No, dmd 0.95
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.objI guess it's good to have a shared backend. ----------------------- Carlos Santander Bernal
May 02 2004
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(); }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.comdmc -c test1.cpp dmd test2.d test1.objI guess it's good to have a shared backend. ----------------------- Carlos Santander Bernal
Jul 13 2004
"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 undocumentedfeature. This is just C++ functions, not C++ objects/methods, right? -david
Jul 13 2004
David Barrett wrote:"Robert Jones" <robertjones21 HotPOP.com> wrote in message news:cd0vg3$ik4$1 digitaldaemon.com...That is what I intend to find out.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 undocumentedfeature. This is just C++ functions, not C++ objects/methods, right? -david
Jul 13 2004
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. ThoasThis is just C++ functions, not C++ objects/methods, right?
Jul 13 2004
Thomas Kuehne wrote:Did you use gdc/gcc to run your test?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.This is just C++ functions, not C++ objects/methods, right?Thoas
Jul 13 2004
Robert Jones wrote: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; }Did you use gdc/gcc to run your test?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.This is just C++ functions, not C++ objects/methods, right?
Jul 13 2004