Regarding: import "foo.h";

Walter Bright newshound2 at digitalmars.com
Wed Jul 17 15:52:41 PDT 2013


Over the years, I've given a fair amount of thought to, and talked about it with 
various people:

    import "foo.h";

or something similar as a way to interface existing C (or even C++) code to D. 
On the plus side, I have a C/C++ front end which could be adapted to do this. On 
the minus,

1. there may be various #define's necessary to compile it that would normally be 
supplied on the command line to the C compiler

2. there are various behavior switches (see the PR for DMD that wants to set the 
signed'ness of char types)

3. rather few .h files seem to be standard compliant C. They always rely on 
various compiler extensions

4. the license would be the same as for the back end

5. having a C/C++ front end as a "bag on the side" of a D compiler seems like a 
heavy burden to anyone wanting to write a D compiler, besides being a fairly 
massive maintenance effort as it would have to be kept up with the latest C/C++ 
standards and extensions

Essentially, I think it is impractical, and in the worst case scenario, could 
actually sink D because of the diversion of effort necessary. Instead, any such 
tool should be a separate tool, designed, built, and maintained separately. 
Perhaps DMD could call it like it calls the linker.


More information about the Digitalmars-d mailing list