Re:C Macro Reflection in Zig – Zig Has Better C Interop Than...
by jay-barronville on Tuesday July 30, 2024 @06:56AM
(#41107843)
> Have you tried D?
I tried D years ago (at least 5 years ago, I think), but I don’t remember experimenting with the C interop.
Your explanation sounds intriguing though. And a couple pretty smart folks I respect have talked about D too. So thanks for bringing it up. I’m going to make some time to experiment with it again some time soon.
> Is that as good as Rust?
Franky, although I don’t have firsthand experience with D, your explanation and example make the D C interop experience sound actually better than Rust’s. It seems more similar to Zig.
Re:C Macro Reflection in Zig – Zig Has Better C Interop Than...
by brabel on Tuesday July 30, 2024 @07:13AM
(#41107931)
I think the feature that allows importing c, called "importC", is newer than 5 years.
I think they may have "copied" it from Zig :D they definitely are trying to not "fall behind" Zig and keep making the language better.
With DMD, you can cross compile just as with Zig, but only to object files as the linker is not multi-platform... so I am experimenting with using Zig's linker to "finish" the job. Unfortunately, Zig is not being able to link Phobos, the D stdlib, for reasons I don't understand yet.
Have you tried D? It can import C files as if they were D modules: https://dlang.org/spec/importc.html
Basically, if there's a `hello.c` file next to your D file, you simply import it with:
And use the functions it provides. You can also import only a subset of it, of course: Or rename the import: The C stdlib is exposed by D's stdlib as if it were a D library: https://dlang.org/phobos/core_stdc_assert_.htmlC libraries (header files) can be compiled to D and then used as D modules as well, see https://github.com/jacob-carlborg/dstep
Is that as good as Rust?