Live data from Hacker News

Next C compiler is a D compiler: Introducing DMD's ImportC

briancallahan.net

51–60 of 89 posts

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#51
post #9

This is just like Zig's C compiler

Zig doesn't have a C compiler yet, it bundles clang. Someone in the community was working towards a C compiler in Zig though. ImportC is basically a C frontend for the D compiler, semantics are close enough but there are some changes to be made still.

The important part in Zig is that you don't need another compiler toolchain to build a mixed C/C++/ObjC project, how that's implemented under the hood (e.g. embedded clang vs self-made compiler) is an implementation detail.

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).

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#52
post #25

Earlier quoted context omitted.

Do you plan on giving Zig a try? (They seem to be doing a lot right.) 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-…

> Do you plan on giving Zig a try? (They seem to be doing a lot right.) All this Zig spam is getting very tiring.

Reminds me of this post just from few days ago[1]. I wish HN had a rule or two dedicated to PL tribalism.

https://news.ycombinator.com/item?id=33382003

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#53

Earlier quoted context omitted.

In a conversation about languages with this kind of C interop, how can you omit Zig?

> In a conversation about languages with this kind of C interop 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.

Instead of being petulant about it, you could ignore it and move on

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#54

Earlier quoted context omitted.

In a conversation about languages with this kind of C interop, how can you omit Zig?

> In a conversation about languages with this kind of C interop 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.

No post body was provided.

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#55
post #25

Earlier quoted context omitted.

Do you plan on giving Zig a try? (They seem to be doing a lot right.) 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-…

> Do you plan on giving Zig a try? (They seem to be doing a lot right.) All this Zig spam is getting very tiring.

No post body was provided.

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#56

Earlier quoted context omitted.

> 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.

Because I am not knowledgeable about D runtime I can not say that it will not cause any conflicts with Rust assumptions (thus the use of "probably"). For example, IIRC there are serious issues with integrating Go code into a Rust project. If D code is compiled in the betterC mode, then there should not be any problems.

You can link in and interop fine with C/C++ as long as you link in the D runtime, kind of how you can mix C and C++ by linking in libcxx.

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.

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#57

Earlier quoted context omitted.

> In a conversation about languages with this kind of C interop 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.

Instead of being petulant about it, you could ignore it and move on

Hard to ignore it when it's always in your face:

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.

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#58

Earlier quoted context omitted.

Zig doesn't have a C compiler yet, it bundles clang. Someone in the community was working towards a C compiler in Zig though. ImportC is basically a C frontend for the D compiler, semantics are close enough but there are some changes to be made still.

Zig does have "translate-c", which attempts to convert C code to Zig code. Similarly to D, it's used for a feature to automatically import C headers into a Zig program. But even that's based on libclang's parser and AST.

ImportC has bitfields and #pragma pack but not translate-c.

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#59

This article is about using the D compiler's ability to import vanilla C code to compile entire C projects.

A lot of people might not know that before doing the D language, Walter was already a world-wide acknowledged expert on the compilation of C and C++. 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.

> A lot of people might not know that

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.

Re: Next C compiler is a D compiler: Introducing DMD's ImportC

#60

Earlier quoted context omitted.

My experience with D is always a joyful one. If it isn't because it is a relatively straightforward language to learn then it is learning something new now and then that just makes life to much more easier. 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).

I wasn't going to add templates to D until I figured out a way to make them simple.

Hey walter, have you thought about adding first class types to the language? that would enable us to use CTFE for type based algorithms instead of templates like std.meta. If you did, what are the reasons against them?
Post reply on HN