Generating .di header files from ImportC files

Walter Bright newshound2 at digitalmars.com
Sat Oct 21 02:13:24 UTC 2023


Bruce and Adam and I met at a Red Robin in Seattle to chat about D, and they 
both made a case for the D compiler being able to translate C files into .di 
"header" files.

The idea is to:

1. be able to work with D IDE programs that can only deal with D code

2. be able to handle the vast bulk of converting .h to D code, and then tweak by 
hand the bits that didn't translate well

Anyhow, I pontificated that this couldn't be done, because some C code is not 
representable as D code. Silly me.

But I got to thinking about it. It turns out that DMD can currently do this:

     dmd -c test.c -Hf=test.di

and voila! It creates a .di file from the C file. Who knew?

It could use some adjustment, but the bulk is there and it didn't crash or 
launch nuclear missiles. (Phew!)

Just like I discovered that ImportC could successfully import and use D code 
(including templates!), this is another fine discovery that DMD can convert C 
code to D code! An unexpected feature that (nearly) comes for free!

Wow!

Anyhow, have fun experimenting with this!


More information about the Digitalmars-d mailing list