A gentle critque..

Sean Kelly sean at f4.ca
Mon May 15 12:46:41 PDT 2006


Chad J wrote:
> Walter Bright wrote:
>> D can link against C code right now, it just will not compile C code.
> 
> Sorry I didn't mean link.  Oh and I said C plus plus a lot, but I think
> the ng cut out the plus plus.  Basically I just want to be able to
> import .h  files and have it just work.

Please be specific.  There's a huge differencec between C and C++
insofar as D support is concerned.

> If it is actually easier to convert all of the C plus plus headers to D
> "headers" by hand than by creating some automated mechanism in the
> compiler, then OK, no full automated conversion.  I find that hard to
> believe though.

To properly convert C headers to D you really need a partial C compiler
that generates D code, which is non-trivial.  C++ header conversion is
another thing entirely, and it simply isn't possible in any reasonable
or portable manner.

If you're truly interested in auto-conversion of D headers, why not
create the tool yourself?  There are open source C front ends available
which should make for a good starting point.

> I am thinking game creation middleware for myself.  This would involve
> hand translating a whole bunch of stuff, just to try it out.  I may not
> even use the results for very long.  I suppose I could code in C plus
> plus to try stuff out, but then I'm doing C plus plus coding and not D
> coding, and that's just about as bad as the header conversion (for me
> anyways).  Then if the maintainers of a C plus plus library change the
> library, the D wrappers become outdated and need fixing.

For what it's worth, you only need to translate the things you need
direct access to from D.  And in my experience, this is substantially
less than what's typically in the header file.  I very much recommend
working from the spec as an indicator of what should be available rather
than simply opening the header file and going for it.  Assuming a decent
spec exists, conversion should go pretty fast.  If no such spec exists,
simply follow the dependencies of any functions you wish to call and do
the conversion on an as-needed basis.  Maintaining such headers should
typically be fairly simple as declarations rarely change across
versions.  Simply diff between the old and new set of headers and see if
any changes are necessary.  Often there aren't.

> I have even more trouble believing that current D compilers shouldn't
> support C plus plus integration just because it might make C plus plus
> compilation a required capability of a D compiler.

*cough*  Are you truly suggesting that it would be trivial to have the D
compiler also compile C++ code?


Sean



More information about the Digitalmars-d mailing list