Next C compiler is a D compiler: Introducing DMD's ImportC
briancallahan.net
briancallahan.net
One of the major appeals of ImportC is that it does away with needing to write (and maintain) D bindings to C libraries -- by hand, or generated.
I was trying to experiment with io_uring in D and using liburing headers included in a C file + ImportC
My D app compiled and ran fine, and I could call liburing but in my editor I was in the dark as to what the methods I could call or their signatures were.
For hardcore vim programmers this is likely the norm, but for me I consider that a step backwards, and I went back to manually generating D bindings and using those.
Waiting for the day we'll see ImportC fully integrated into dub and pure-d/workspace-d!
Just FYI, not anymore.
Going to give ImportC a spin there!
Taking the opportunity here to point people to "Adding Modules to C in 10 Lines of Code" from NWCPP earlier this year:
<https://www.youtube.com/watch?v=2ImfbGm0fls>
(The pitfalls you mention running into there wrt to different compiler instances is itself a decent case study in not relying on singletons <http://www.object-oriented-security.org/lets-argue/singleton...>—even if it ultimately wasn't so inconvenient that the work never got done, it would be even more convenient if it didn't need to have been done in the first place!)
All this Zig spam is getting very tiring.
It's not. It's a discussion about "the C compiler built into the Digital Mars D compiler".
Please stop with all the Zig spam.
https://news.ycombinator.com/item?id=33331549
I don't mind languages getting hyped but seeing posts every week on the front page of HN about an unstable esoteric language with 0 adoption - yes, it's getting tiring.
- https://news.ycombinator.com/item?id=33337381 (posted from a 12-year-old account)
- https://news.ycombinator.com/item?id=33333904 (posted from a 2-year-old account)
simplotek is most probably a legitimate user annoyed by Zig news. I don't agree with their point, for what it's worth, but at least it's an opinion shared earnestly, unlike the troll.
Not wanting to see gratuitous self-promoting spam degrading the signal/noise ratio of an otherwise interesting discussion is hardly petulance. Replace any Zig reference shoe-horned into this discussion with, say, Java, and see if you have any point.
Even all that aside, comparing and contrasting contemporaries in a similar space is natural. That's just, like, scholarship, you know? Imagine someone who's defending their thesis responding to a question about alternatives to their research by getting into a big huff about it. That'd be pretty silly, right?
And the comments about "PL tribalism" are a little odd, then, since the most tribalistic behavior we have evidence for in this thread is someone reacting exactly like this. As a fan of Walter's contributions, including D, in the past I've gone so far as to put a non-trivial amount of effort into polishing the articles on D, Walter, and Digital Mars on Wikipedia. Meanwhile, I've never even written a Zig program, dude; if there's a tribe I belong to, it's not Zig.
It is Zig spam, not because of the discussion or the question or the topic of the time of day. It's Zig spam because it's yet another Zig post among the barrage of Zig posts desperately shoe-horning offtopic gratuitous references to Zig. It's tiring and adds nothing to any discussion.
If you feel that strongly about the need to promote Zig, submit discussions. Please don't spam each and any top submission with these gratuitous references.
What I responded to was a comment from D's own creator who himself directly mentioned Zig. I didn't shoe-horn shit. I've been waiting a long time for a hit on Corncob TV.
If you're upset about Zig mentioned here, your quarrel is not with me, the person who spent over half the words in their comment bringing it back to the original topic by linking to a useful talk; your quarrel is with, if anyone, the original questioner who got Walter to comment on Zig. (And even then, your ire would be tenuous at best, for the reasons already mentioned.) I also cannot "feel that strongly about the need to promote Zig"—because I am not promoting Zig. As I have already said, D is closer to my tribe than Zig is.
I don’t use D seriously but I’d still bet my ass that something smart happens when you feed C code to the D compiler toolchain.
Personally, that would surprise me, because C++ compilers is the context where I first read the name. I'm not saying this is incorrect, but I would find it amusing somehow.
I'd be much less annoyed by it if dang finally made it a pre-submit check (maybe with a checkbox "Overrule") like the "too long" check. But no, it seems to be important that the submitter has to check manually whether the title he just typed in is still there.
Infact, D was the first language I learnt templating in and I really like it (or rather, the way D goes about it - made it much more approachable for me).
The syntax for inferring a type for function calk arguments is nifty too.
Lastly, today I finally understand what mixins are , I just read some stdlib file somewhere and thought, wow that's rather useful. I definately think I will be making use of mixins sometime soon, been working on a small compiler in D itself and there are times were duplication (or perhaps inclusion is a better word) of code would be nice in such a manner.
More broadly, are there plans to support C extensions that are available in GCC and clang?
I guess only a subset of C11 is supported? Is there all of C89?
For instance check out this call to create a 3D-API pipeline-state-object in C99:
https://github.com/floooh/sokol-samples/blob/ad9047e228a8441...
https://github.com/floooh/sokol#sokol_gfxh
I couldn't live without it
https://dlang.org/spec/struct.html#static_struct_init
D support it, what's blocking it?
I forecast that as it’s pragmatic, industrial uses (inevitably) grow sharply, that the FFI story will just have to improve. Rust is going to be the next “low-level” language.
The “Pure Rust” talking point will have to recede a bit but it will be a net win for Rust’s truly broad adoption, which is going to happen whether cranky old-timers like me like it or not :)
How is acknowledging that Rust is clearly and obviously the next big thing an insult to anyone.
It’s not my favorite language but it’s a good one and I know it’s going to displace C/C++ in my lifetime. What more does the downvote brigade want?
Using D code in Rust probably will be much more painful and I am not sure if it can be done 100% safely...
Can you elaborate? Saying it will be "much more painful" without anything further is not especially helpful. I've added D functions to C programs more or less trivially, including compiling to a shared library, with no change to the code.
D's betterC mode ensures that the binary can run purely on libc without D's runtime library. It's kind of like being able to link and execute C++ code without needing libcxx.
You can just as easily declare D code to be extern(C) and have rust treat it as a C library.
1. We can support it, I suspect no headers will go near it for a while but we can.
2. C23 support actually brings some C semantics closer to D ones anyway...
Is head const now supported in DMD with ImportC?
is that included with the DMD installer? If not thats the same situation as LDC.
your daily edition of WalterBrightFacts™
I never did find out who did it. I wonder if it was Walter?
I was an overly obnoxious frosh at the time and I'm certain I was quite annoying to the older students who frequented the terminal room such as Walter (I think he would have been a junior at the time).
And I'm certain Walter was aware of me, because he had once either targeted me in a prank or used me in a prank against someone else (or perhaps both--I've never been clear on who was the target). The someone else was one of the system admins, Bill. Bill really liked playing Walter's game "Empire".
So one day I was sitting at a terminal hacking away at something and I got a message via the system for sending a text message to another terminal from Bill telling me to not do what I just did again or I'd be in trouble and have my account suspended.
I had no idea what he was talking about. A while later I got another message. Bill seemed really annoyed with me. I then got summoned to his office. He was really mad. He said I keep sending him rude messages, like telling him to stop playing Empire and get his fat ass back to work.
I denied sending these messages and he was not buying it.
And then another insult from me came through while I was there in his office.
Bill then started to maybe believe me, and went to Walter's directory to look at the Empire source. Sure enough, Walter had recently added code that checked for Bill playing while I was also logged on, and would fake rude and insulting messages from me from my terminal to Bill.
And that is why I will never use a compiler from Walter if there is any way the compiler might be able to tell I'm the one using it. :-)
https://dlang.org/blog/2017/07/07/go-your-own-way-part-one-t...
ImportC is basically a C frontend for the D compiler, semantics are close enough but there are some changes to be made still.
I'd argue that C++ and ObjC support is just as important as C support for real world projects (because a lot of important libraries are written in C++ unfortunately, and ObjC is needed for calling into macOS system APIs - although this could also be done more awkwardly by going through the ObjC C runtime).
The one big downside of embedding Clang and the whole of LLVM is the compiler's executable size (somewhere around 170 MB).