On Friday, 23 January 2015 at 11:04:12 UTC, Walter Bright wrote:
Mandatory reddit link:
http://www.reddit.com/r/programming/comments/2tdy5z/interfacing_d_to_legacy_c_code_by_walter_bright/
There's been a lot of interest in this topic.
Interesting...
I wonder if two things could happen:
1. A tool could be written to generate the interfacing code in D
from the C++ code?
2. If, in your stl example, the default argument could be
automatically inferred from the mangling?
What I mean is, Do we really need to know the default arguments
or are we just having to explicitly use them to make the name
mangling work?
If it is the latter, then surely couldn't the D compiler sort of
have a "wild card" type of default parameter where the compiler
allows any such argument to work?
i.e., unless we are actually explicitly needed the default
argument in some way it seems that we can just derive it's
"mangled" version from the C++ object data and use that directly
in the D mangled version?
Essentially the D compiler mangles what it can then substitutes
the part of the mangled name in C++ for "unknown things" into the
D mangled name.
I just see that if we are "linking" then why would one have to
"implement" anything? Just essentially "Copy" the mangling from
C++ object data.
3. Hopefully a mapping table is used instead of having to
actually have implementations for very compiler?
e.g.,
essentially implement a standard ABI in D, map each C++ compilers
mangling version to that instead of implementing each C++
compilers mangling.
It seems that 99% of the problem is translation in nature and
that one can auto generate D interfaces from C++ mangled names.
(in fact, one could go a "step" further then and simply reverse
C++ object code into D code)