View mode: basic / threaded / horizontal-split · Log in · Help
May 03, 2004
d and c++
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
July 13, 2004
Re: d and c++
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
July 13, 2004
Re: d and c++
"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
July 13, 2004
Re: d and c++
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.
July 13, 2004
Re: d and c++
>> 
>> 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
July 13, 2004
Re: d and c++
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
July 13, 2004
Re: d and c++
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;
}
Top | Discussion index | About this forum | D home