Vala could replace C ... (h2d)

Anders F Björklund afb at algonet.se
Mon Sep 3 23:57:47 PDT 2007


Walter Bright wrote:

>> FWIW, D's compatibility with C is better than that of most languages.  
>> This doesn't make it good.  I understand the problem caused by macros 
>> in header files...but they are a severe impediment to "very easy 
>> compatibility".  "Very easy compatibility" (my definition) means that 
>> I take of chunk of C code in multiple separate files linked by header 
>> files, and replace on of the files with a chunk of D code that 
>> performs an equivalent function.  This isn't possible, and probably 
>> isn't going to be possible.  At any rate, not until interpretation of 
>> C header files is handled.
> 
> The h2d.exe program will convert C headers to D import files. It isn't 
> perfect, but it does a pretty good job of it.

While it is possible to run h2d.exe using Wine, there are also some open
source and free software like the h2d.pl hack or the bcd.gen program...

http://www.algonet.se/~afb/d/h2d.pl (GD, GL, AL, SDL, Tk, etc. etc.)
http://www.dsource.org/projects/bcd (fltk2, gtk+, libxml2, etc. etc.)

It's nowhere as convenient as with C-compatible languages like C++ or
Objective-C where you can do a #include, but it usually does the trick.
(and once the initial D import module has been created, it normally only
needs minor patches to keep up with version updates from the C header)

The real issue is C++ headers, where it is needed to generate one C++
file with extern "C" and one D wrapper that calls these function stubs.
Or with system headers that aren't distributable, or other secret stuff
where everyone has to re-generate their own bindings instead of sharing.

For instance with libraries like wxWidgets, you run into both of these.

--anders



More information about the Digitalmars-d-announce mailing list