Reputation: 1698
Let's say I have two source files, one written in the D programming language and the other one written in the C programming language. I both just compile them, the D source with the DMD (Digital Mars D-Compiler) and the C source with the GCC compiler.
The result will be two .o (object) files which originated from a different source. Is it possible to link these two files into one executable?
Upvotes: 0
Views: 445
Reputation: 11791
That depends on lots of things. There are different ways of handling arguments: The caller sets them up, the callee cleans up (Pascal-style in Windows, more compact); or the caller sets up and cleans up (C style, uses more space as the cleanup is repeated for each call site). Arguments can be passed by value or reference. Data (particularly arrays and structures) can be laid out differently in memory. From a rapid look at D's homepage it has stuff like inmutable data and native associative arrays, that would have to be matched in C (and probably requires linking in D's runtime, and unless that one builds on your system's C library you'll be in a lot of pain). And so on. If you know details of how things are done, you can certainly provide the necessary glue and missing compiler support functions, but easy it won't be. In case of GCC compilers there are guarantees and commonalities that help, for unrelated compilers it is probably more of a gamble. There is a LLVM based D compiler, which I'd guess has more chance of working with gcc, as one of clang's objectives is GCC compatibility.
Upvotes: 0