The forked elephant in the room

Walter Bright newshound2 at digitalmars.com
Mon Jan 29 06:14:19 UTC 2024


On 1/28/2024 7:35 PM, Don Allen wrote:
> Zig also has the ability to translate C headers into Zig. The result is very 
> similar to ImportC. I believe I mentioned this to you when ImportC first became 
> available.

You probably did.


> I think this is an important capability for both languages. Added to the ability 
> to call C libraries directly, it makes direct access, without binding libraries, 
> to C libraries possible. I think your decision to implement ImportC was a good one.
> 
> I've done quite a bit of gtk3 work in Rust. The Rust gtk "crate" is insanely 
> complex and poorly documented (sometimes even inaccurate, where they generate 
> the documentation using snippets from the original gtk3 docs, sometimes 
> including memory-management things that are not necessary in Rust), unlike gtk3 
> itself. I much prefer working directly with gtk3 in D. I did the D work before 
> ImportC was available, so wrote my own D function prototypes. Even that was 
> preferable to wrestling with the Rust "crate" and I'm sure ImportC would have 
> made the job a lot easier, if it is up to dealing with the gtk header files. I 
> have tried ImportC with sqlite and that works just fine.

I'm glad it's working for you!

D can actually translate C to D, as well. Just add the switch for .di file 
generation, and the C code will be emitted as D! Adam Wilson prefers to use it 
this way rather than keep importing the .h files.

I warned Adam that this was imperfect, as C semantics don't exactly line up with 
D semantics. But he's well aware of that, and it isn't a problem for his work.


More information about the Digitalmars-d mailing list