4 ms·
Me too. > To me it's the clear choice if I'm going to rewrite an old C project since I can mostly just copy paste the old code and it runs With the new Import
by gavinray 5y ago
Me too.
> To me it's the clear choice if I'm going to rewrite an old C project since I can mostly just copy paste the old code and it runs
With the new ImportC feature you can literally copy-paste the code and reference your C types from D directly with a mixed compilation.
https://news.ycombinator.com/item?id=27872596 https://news.ycombinator.com/item?id=27872596
https://dlang.org/spec/importc.html https://dlang.org/spec/importc.html
Quoting Walter from the thread linked above on it's purpose/reasons (which I think ought to go somewhere official tbh, since that brief discussion in the above thread is the best + most succinct overview of it currently AFAIK)
The reasons for ImportC are:
1. It's no longer necessary to translate .h files to D to interface with C. While doing the translations isn't hard, it is tedious, and if there are a lot of .h files it becomes a barrier.
2. .h files get updated over time, and correspondingly updating the D files is error prone. It's much more effective to just compile the new .h files.
3. It is not necessary to even create a .h file - just compile the .c file with ImportC and D will access it just like any other module. D will even inline the C functions in it.
4. Use it as a standalone, small and fast, C compiler.
- 59nadir 5y ago`@cImport` in zig does the same as `ImportC` for D. You import a C file and can then just use it in your program. Notably it existed in Zig before it did in D.