News for hackers. Stuff that matters.
Re:Aro – Zig's new C compiler by WalterBright on Saturday July 20, 2024 @02:21PM (#41018489)
The dlang D compiler includes a full C compiler, so you can mix and match C and D code. You can import C code from D, and D code from C.

    dmd hello.c
    ./hello
    hello world
This helps enormously in binding to existing C libraries.
Re:Aro – Zig's new C compiler by nequo on Saturday July 20, 2024 @03:52PM (#41019223)
How exactly does this relate to the post, Aro, other than this also being a C compiler? Could you draw a comparison for those who came here for Zig and not D?

What conclusion should we draw about Aro based on what you’re saying?

Re:Aro – Zig's new C compiler by WJW on Saturday July 20, 2024 @05:15PM (#41019999)
It doesn't relate to Zig at all, but Walter Bright is the creator of D and tremendously proud of it.
Re:Aro – Zig's new C compiler by nequo on Saturday July 20, 2024 @05:19PM (#41020033)
I know that he is but this is incredibly off-topic. Aro deserves the attention it is getting, without the discussion getting hijacked by another project.

D would deserve attention too, in a separate post, or here if it was explained how it relates to Aro.

Re:Aro – Zig's new C compiler by jraph on Saturday July 20, 2024 @06:21PM (#41020553)
Walter's comment could be read more charitably and could show his interest in Zig and similar choices that are made.

The last sentence, or, indeed, the whole comment, can be read like "We did this for D, and it works well. [go for it]".

I don't think D is casting any shadow on Zig. Both languages play in the same field, D is older but I feel like we hear about Zig way more these days.

His comment is likely to interest people interested in Zig or PLs in general.

The comment as is might lack some finesse but I don't think it deserves this level of aggressiveness.

Re:Aro – Zig's new C compiler by bithavoc on Saturday July 20, 2024 @06:53PM (#41020770)
I have profound respect for Walter and all his work, same for Andrei; but his comment was off-topic.
Re:Aro – Zig's new C compiler by pests on Saturday July 20, 2024 @07:45PM (#41021160)
His post does seem self-promotional I admit but Walter usually shows up in any threads about compilers and usually shares interesting comparisons and contrasts to how his language and compiler handled the issue.

For me, I appreciate the perspective and opinions of someone else in the industry with proven results. D is a major language, you can't deny that.

Maybe this post he should have went into a little more detail but I do not think he posted this with ill intent.

If anything I'm sure he would love to continue a dialog about the design decisions that led him to implement the same feature - and maybe this was his way of starting the conversation.

Given that he is a 15 year member of our community, and has earned 70k karma, we should give him the benefit of the doubt.

Re:Aro – Zig's new C compiler by WalterBright on Saturday July 20, 2024 @11:43PM (#41022212)
> he should have went into a little more detail

If there's interest, I can give more detail.

Re:Aro – Zig's new C compiler by fuzztester on Saturday July 20, 2024 @09:24PM (#41021635)
>I know that he is but this is incredibly off-topic.

no, it is not. in the fine tradition of hn, let me reply by saying, "that's like, just your opinion, man". which is not worth more than any other people's opinion on this site. maybe worth less.

e.g.:

>D would deserve attention too if ...

so now you are telling everyone what deserves attention?

then what have you done to deserve attention yourself (to your comments, that is)?

walter has done plenty. he created the D language, and still maintains it, along with others, like, you know, Andrei, for one. Google who that is.

Google about Walter to know what other stuff he has done before, like you know, the Zortech C++ compiler.

Re:Aro – Zig's new C compiler by nequo on Saturday July 20, 2024 @10:12PM (#41021856)
Let me just say, your comments have not been the most constructive I’ve read.
Re:Aro – Zig's new C compiler by fuzztester on Sunday July 21, 2024 @12:01AM (#41022282)
Sure, I will let you say it :)

Let me say that I think the same about this comment of yours upthread:

>>D would deserve attention too, in a separate post, or here if it was explained how it relates to Aro.

(still editing)

In case you cannot or don't want to google for some reason, here are the Wikipedia articles about Walter and Andrei, and important related topics (all on Wikipedia, which implies noteability) that I suggested you look up, above:

https://en.m.wikipedia.org/wiki/Walter_Bright

https://en.m.wikipedia.org/wiki/Zortech_C%2B%2B

https://en.m.wikipedia.org/wiki/Empire_(1977_video_game)

https://en.m.wikipedia.org/wiki/D_(programming_language)

https://en.m.wikipedia.org/wiki/Andrei_Alexandrescu

https://en.m.wikipedia.org/wiki/Modern_C%2B%2B_Design

https://en.m.wikipedia.org/wiki/C%2B%2B

Re:Aro – Zig's new C compiler by klyrs on Sunday July 21, 2024 @08:47AM (#41024702)
Sorry, but what does this have to do with Aro?
Re:Aro – Zig's new C compiler by fuzztester on Sunday July 21, 2024 @06:14PM (#41028718)
Sigh.

See here for one way to get it, i.e. someone else's comment on the topic:

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

If that doesn't help, start reading from the start of this subthread that starts with Walter Bright's comment about D, and pay attention throughout, otherwise don't waste your time commenting.

If even that doesn't help, nothing will; sorry, I don't have the time to explain things more than that, for a trivial matter like this.

Re:Aro – Zig's new C compiler by klyrs on Monday July 22, 2024 @11:29AM (#41035573)
> sorry, I don't have the time to explain things more than that, for a trivial matter like this.

Au contraire! You're contributed more to this sideshow than anybody: context I was fully aware of when I asked my rhetorical question.

Oh, and you probably know this in the abstract, but your patronizing tone really isn't doing your case any favors here.

Re:Aro – Zig's new C compiler by fuzztester on Tuesday July 23, 2024 @07:00PM (#41051905)
>> sorry, I don't have the time to explain things more than that, for a trivial matter like this.

>Au contraire! You're contributed more to this sideshow than anybody: context I was fully aware of when I asked my rhetorical question.

>Au contraire!

Merde! Mon Dieu! Gesundheit! (Hey, Duo, you buggy bro! that's DE, not FR) :)

I can talk fancy French too, with the help of my French mistress, aka Google Translate(ss) :) :

ton discours fantaisiste ne me dérange pas, mon garçon

original in English, by me:

your fancy talk does not faze me, boy

https://translate.google.com/?sl=en&tl=fr&text=your%20fancy%...

>sideshow

if it's a sideshow, why did you participate in it? you are a serious guy, right?

me, I am a dumbass, and just having fun.

>context I was fully aware of when I asked my rhetorical question.

I don't believe it. you are trying to CYA.

but anyway, rhetorical questioners should expect to get any kind of answers, including unexpected ones.

see ya. ciao.

wow, those last two words of mine, they kind of rhyme.

I should take up a career as a poet, since it's already a vocation, after I've spent some of my millions taking a vacation.

signed,

- funster.ai

in Westminster, bye bye.

# everything has to be AI nowadays, otherwise people don't pay attention. that's the usual convention. it's a source of dissension.

Re:Aro – Zig's new C compiler by bpmooch on Sunday July 21, 2024 @12:48PM (#41026310)
He's right, what he's saying is just so obvious it's annoying it has to be said in reply to low effort posts like yours
Re:Aro – Zig's new C compiler by fuzztester on Sunday July 21, 2024 @06:18PM (#41028754)
thanks. you are one of the few people among the commenters who got what I was saying in this thread, I mean. I am sure tons of other sensible people here understood it but did not comment, because it was not worth their time to comment on something so obvious, as you said above, in reply to nequo above.
Re:Aro – Zig's new C compiler by fuzztester on Saturday July 20, 2024 @09:20PM (#41021621)
Jeez!

The post title is "Aro, Zig's new C compiler", not just about Aro or Zig. In fact, just by virtue of being about Aro, it is also about C compilers - as the title clearly says, whether you (pedantically) like it or not. And D is a language that is used as a better C too, apart from other things. In fact, lang C -> lang D, says something significant to this discussion, right?

>Could you draw a comparison for those who came here for Zig and not D?

Sigh.

More pedantic talk.

Shall we start drawing Venn diagrams to clarify things?

Is it not possible that there can be different groups of people, some of whom are interested in Zig, others in Zig and Aro, others in C compilers generally, and others in D with some of those groups overlapping? That's what Venn diagrams are meant to show.

Re:Aro – Zig's new C compiler by F3nd0 on Sunday July 21, 2024 @09:52AM (#41025099)
And just by virtue of being about C compilers, it is also about C, thereby making all talk about programming languages on-topic? I see your point about other C compilers being related, but following this line of thought, most any topic could be generalised to whatever you want.

Generally speaking, the more you stray from the most concrete topic at hand (in this case Aro and only Aro), the more it becomes appropriate to explain and elaborate on the relation between that and whatever you've decided to talk about instead. In my view, anyway.

Re:Aro – Zig's new C compiler by fuzztester on Sunday July 21, 2024 @06:32PM (#41028875)
your logic in the first sentence of your first paragraph is quite faulty.

how did you jump from C to all programming languages, in the context of that statement? I did not say anything of the kind.

I can't waste my time explaining things multiple times to different people who don't get it, when others have got it.

maybe check my answers to the other people in this subthread, if you are that interested, for what is such a trivially obvious matter.

good luck.

Re:Aro – Zig's new C compiler by F3nd0 on Sunday July 21, 2024 @08:27PM (#41029713)
> how did you jump from C to all programming languages, in the context of that statement? I did not say anything of the kind.

Simply by taking further steps in the same direction. The submission is about Aro, and therefore comments about Aro are on-topic. By your own stated logic, Aro is a C compiler, and therefore comments about other C compilers are also on-topic. One could then go on to say that C compilers in turn pertain to C, and C in turn is a programming language, therefore rendering all comments about programming on-topic under a submission about Aro.

Granted, the example is a bit of a hyperbole, and I doubt anyone would really jump that far. But I find your assertion that a submission about a program (in this instance Aro) renders comments about all other programs of the same kind (in this instance C compilers for other languages) on-topic to be much in the same vein.

> I can't waste my time explaining things multiple times to different people who don't get it, when others have got it.

> maybe check my answers to the other people in this subthread, if you are that interested, for what is such a trivially obvious matter.

I have, of course, read your other comments, but haven’t found anything that would help me understand or accept your argument (assuming that is what I'm supposed to ‘get’). I suppose it's not so ‘trivially obvious’ to me. Don't feel obliged to elaborate any further if you feel that's a waste of your time, though. Good luck!

Re:Aro – Zig's new C compiler by fuzztester on Sunday July 21, 2024 @10:08PM (#41030275)
Seems like multiple instances of either unintentionally poor logic, intentionally fake logic, or just weasel words, on your part, in your above comment that I am replying to.

Here is one, i will not go into others:

>>how did you jump from C to all programming languages, in the context of that statement? I did not say anything of the kind.

>Simply by taking further steps in the same direction.

but i did not ask you to take further steps in the same direction, so that you could twist my words.

i limited myself to C and closely related topics, like D, C++, Walter, and Andrei - related languages and people involved with them.

don't try to twist my words, as you appear to have done above.

yes, once i find people talking fake or not understanding, it is a waste of my time, so i will not engage further with you.

Re:Aro – Zig's new C compiler by F3nd0 on Monday July 22, 2024 @12:23AM (#41030921)
> but i did not ask you to take further steps in the same direction, so that you could twist my words.

I took them to paint an example, so that my argument could be better understood. The example was clearly presented as my own; I have twisted no words of yours from what I can see, and I most certainly wasn't trying to.

> i limited myself to C and closely related topics […]

Yes, while the submission is about Aro, not C, hence the disagreement.

> […] so i will not engage further with you.

Thank you, I suppose.

Re:Aro – Zig's new C compiler by binary132 on Saturday July 20, 2024 @04:10PM (#41019385)
I would 100% be a D user if it had full C++ typesystem fluency.
Re:Aro – Zig's new C compiler by WalterBright on Saturday July 20, 2024 @10:00PM (#41021801)
D has a lot of compatibility with C++'s type system. But not with everything - for example, D does not have a `volatile` type. What is missing that you're interested in?
Re:Aro – Zig's new C compiler by binary132 on Monday July 22, 2024 @10:17AM (#41034677)
I know, and that’s a major selling point for D in my book; iirc it’s what led me to explore D in the first place. Hardly any languages have good C++ interoperability. I was following Calypso with great interest for a while, but sadly it looks like the author lost momentum, so it never got exception handling for MSVC.

What I need to work reliably from C++ are 1. instantiation of imported templates, ideally including CRTP, and 2. handling in D of exceptions thrown from C++, because if I use a C++ library that throws, I need to be able to handle the exception.

So far I’ve found languages that can import template classes and functions from C++ (usually by extending LLVM/Clang), but no languages that have good, reliable cross-platform C++ exception handling.

Re:Aro – Zig's new C compiler by Daunk on Saturday July 20, 2024 @03:28PM (#41019030)
D is so underrated. Keep up the good work Walter.
Re:Aro – Zig's new C compiler by throwaway2037 on Sunday July 21, 2024 @12:44AM (#41022437)
I am pretty sure that most of the language design is done by Andrei Alexandrescu now.
Re:Aro – Zig's new C compiler by brabel on Sunday July 21, 2024 @04:43AM (#41023497)
Not at all. Walter is the "boss", Andrei left as a leader in May 2019: https://www.youtube.com/watch?v=cpTAtiboIDs&t=3049s
Re:Aro – Zig's new C compiler by pjmlp on Sunday July 21, 2024 @07:28AM (#41024299)
Andrei Alexandrescu is back focusing on C++ at NVIDIA.
Re:Aro – Zig's new C compiler by brabel on Saturday July 20, 2024 @02:28PM (#41018542)
Is it possible to do what Zig does and cross compile to any OS/arch, from any OS/arch?

Last I tried, I found some compiler options and commands to do it, but they were badly explained, I tried for hours and it just didn't work at all, so I gave up.

Re:Aro – Zig's new C compiler by WalterBright on Saturday July 20, 2024 @02:39PM (#41018621)
The dmd D compiler can cross-compile to any of the targets that it supports. I use it all the time to develop on other platforms.

I am currently adding AArch64 support to DMD's code generator. dmd doesn't run on my Raspberry Pi (yet!), so I use sshfs to access the Pi's filesystem from Ubuntu, compile programs on Ubuntu, transfer the .o file to the Pi, link it on the Pi, and run it on the Pi.

I'm sorry you're having trouble with this, so I recommend posting on the D forums, and people are there to help!

https://forum.dlang.org/

Re:Aro – Zig's new C compiler by wyldfire on Saturday July 20, 2024 @03:44PM (#41019174)
The grandparent post refers to the fact that Zig ships with C, C++ library source that it lazily cross-builds (at least for linux, I don't recall how it solves this problem for macOS or windows). And possibly it uses lld too? Since Zig ships with these, it makes the whole cross-build experience much smoother and less dependent on whether your host OS distribution includes packages for your desired target OS/architecture.
Re:Aro – Zig's new C compiler by brabel on Saturday July 20, 2024 @03:53PM (#41019231)
Exactly. Zig tooling includes a linker, and that's also cross-platform. Zig can generate actual runnable executables that run anywhere from a single machine.

As far as I can tell, D's DMD can cross compile but not link. I probably missed that before (actually, I think I was trying with LDC, I found the page where they document the process while searching for it just now: https://wiki.dlang.org/Cross-compiling_with_LDC if you try those options, nothing works, at least from MacOS).

I just tried and this only works with the -c option (compile, but not link):

    dmd -os=linux -c source/app.d
Without `-c`:

``` Error: linker exited with status 1 cc app.o -o app -m64 -Xlinker -no_compact_unwind -L/Users/me/dlang/dmd-2.109.1/osx/bin/../lib -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm (dmd-2.109.1) ```

I am sure Walter knows how to compile on one machine, then go to another machine and do the linking or whatever is needed. I know nothing about those, but with Zig I need not know anything other than which flag to use to cross compile. It's a huge difference. D should do that, otherwise it's just not competitive for people like me (I am just an average joe programmer who knows how to write code but has very little interest in learning how linkers work).

Re:Aro – Zig's new C compiler by wyldfire on Saturday July 20, 2024 @04:10PM (#41019388)
> I am sure Walter knows how to compile on one machine, then go to another machine and do the linking or whatever is needed.

Historically, you would or at least could get your compiler and linker from different vendors -- assembler, disassembler and other tools too. So it's normal/common for C compilers like gcc, clang, dmd to not be distributed like Zig is.

But I would dare say that the way Zig is doing it is a great model for others.

> go to another machine and do the linking

BTW - if you use something like debian/ubuntu for development, they have compilers+linkers+binutils for several different architectures available to make cross-building without Zig at least a little bit easier.

Re:Aro – Zig's new C compiler by kubkon on Sunday July 21, 2024 @04:54AM (#41023550)
FYI, Zig is in the process of dropping dependence on lld on Linux and Windows; macOS uses Zig's own linker since roughly 2021 as far as I recall. Tracking issue for reference: https://github.com/ziglang/zig/issues/8726
Re:Aro – Zig's new C compiler by WalterBright on Saturday July 20, 2024 @09:58PM (#41021794)
A cross-linker would be required for that to work. If you use a cross-linker with D, it should work.
Re:Aro – Zig's new C compiler by brabel on Sunday July 21, 2024 @04:50AM (#41023529)
Given Zig has one, it might actually be possible to delegate to that then?

It would be awesome to have a post explaining how to do that :)

Re:Aro – Zig's new C compiler by zellyn on Sunday July 21, 2024 @09:37AM (#41024991)
The older “cross compiling Go with Zig” post might give a good start if you want to figure it out
Re:Aro – Zig's new C compiler by brabel on Sunday July 21, 2024 @01:27PM (#41026582)
I had a look at the post. It only shows how to tell the Go compiler how to use Zig as the C Compiler. In our case, what we need is to tell Zig to link the object files created by D.

I've had a look and saw that Zig is still implementing the `ld` command, but there's already a `ld.ldd` command which might work if you know what magical options to use. I've tried to link my D object file but it can't find a whole lot of generated symbols, and a quick search online does not tell me where do I get those symbols from. That's always what happens when I try to do stuff with D that's not well documented.

I tried this (used the dmd -v option to get the linker command):

    zig ld.lld -L/Users/me/dlang/dmd-2.109.1/osx/bin/../lib  app.o
Output:

```

ld.lld: error: undefined symbol: _d_assert_msg >>> referenced by myd/source/app.d >>> app.o:(_D4core8internal5newaa__T6makeAATAyaTiZQoFNaNeHQoiZSQByQBwQBq7AAShell) >>> referenced by myd/source/app.d >>> app.o:(_D3std6format5write__T14formattedWriteTSQBm5stdio4File17LockingTextWriterTaTS3app__T9StringMapTiZQnZQDaFNfKQCqMxAaQBmZk) >>> referenced by myd/source/app.d >>> app.o:(_D3std6format5write__T14formattedWriteTSQBm5stdio4File17LockingTextWriterTaTS3app__T9StringMapTiZQnZQDaFNfKQCqMxAaQBmZk) >>> referenced 27 more times

ld.lld: error: undefined symbol: _aaLen >>> referenced by myd/source/app.d >>> app.o:(_D4core8internal5newaa__T6makeAATAyaTiZQoFNaNeHQoiZSQByQBwQBq7AAShell) >>> referenced by myd/source/app.d >>> app.o:(_D3std6format8internal5write__T15formatValueImplTSQBw5stdio4File17LockingTextWriterTHiHAyaiTaZQClFNfKQCaQuMKxSQEeQEd4spec__T10FormatSpecTaZQpZv) >>> referenced by myd/source/app.d >>> app.o:(_D3std6format8internal5write__T15formatValueImplTSQBw5stdio4File17LockingTextWriterTHAyaiTaZQCjFNfKQByQsMKxSQEcQEb4spec__T10FormatSpecTaZQpZv)

ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)

```

Do you know how to get past that?

Re:Aro – Zig's new C compiler by WalterBright on Sunday July 21, 2024 @07:30PM (#41029344)
Looks like the D runtime library isn't being linked in.
Re:Aro – Zig's new C compiler by zellyn on Monday July 22, 2024 @10:58AM (#41035221)
I have to confess to mostly just lurking Zig with interest, but not _actually_ knowing what I'm talking about. I do know their linker game has improved a _lot_ since that old Go article, so it's quite likely that Zig can do what you want. You might want to try their IRC or Discord.
Re:Aro – Zig's new C compiler by o11c on Saturday July 20, 2024 @03:30PM (#41019054)
Generally, the hard part isn't the cross compiler (nor, these days, the cross binutils), but the cross libraries. There are at least 3 ways (/usr/lib/$ARCH, /usr/$ARCH/lib, /$CHROOT/usr/lib/) to set up the libraries, all incompatible with each other.

Zig is notable for putting a lot of work into hard-coding basic C libraries, though of course you still need a scattering of other C libraries for most real-world programs.

(for a sufficiently advanced language ecosystem, the language's own libraries should be easy enough)

Re:Aro – Zig's new C compiler by wucke13 on Saturday July 20, 2024 @07:11PM (#41020900)
The nixpkgs have a rather elegant way to deal with that. Let's presume you need a libpng for an armv7 platform, such as an old RaspberryPi. Then Nix allows you to

- get a suitable cross compiler toolchain

- pick whether you want dynamic or static linking (most likely static when the target system does not come with /nix/store)

- compile all prerequisites for the library such as transitive dependencies

- compile the library with the cross compiler for the selected target arch

All in one command line call, that does not require you to 'apt-get install' any of the tools manually:

  nix-build '<nixpkgs>' -A pkgsStatic.libpng --arg crossSystem '{ config = "armv7a-unknown-linux-gnueabihf"; }'
Re:Aro – Zig's new C compiler by Cloudef on Sunday July 21, 2024 @01:35AM (#41022663)
You can combine zig and nix with <https://github.com/Cloudef/zig2nix> (shameless plug)
Re:Aro – Zig's new C compiler by fuzztester on Saturday July 20, 2024 @09:05PM (#41021576)
Interesting, good to know.
Re:Aro – Zig's new C compiler by WhereIsTheTruth on Saturday July 20, 2024 @11:39PM (#41022194)
I was about to say this, and DMD compiles C code insanely FAST!
Re:Aro – Zig's new C compiler by flohofwoe on Sunday July 21, 2024 @04:59AM (#41023568)
...I mean Zig has those features too since the beginning with `zig cc`, translate-c and @cImport (currently via an embedded Clang), but the post is about an indepdent C compiler written in Zig (but which will most likely replace Clang as the embedded C frontend once Clang/LLVM isn't compiled into the Zig compiler anymore).