News for hackers. Stuff that matters.
Re:Resigning as Asahi Linux project lead by cratermoon on Thursday February 13, 2025 @12:09PM (#43038330)
I'm curious now. What are the backwards compatibility guarantees for C?
Re:Resigning as Asahi Linux project lead by cornstalks on Thursday February 13, 2025 @12:14PM (#43038417)
As long as you compile with the version specified (e.g., `-std=c11`) I think backwards compatibility should be 100%. I've been able to compile codebases that are decades old with modern compilers with this.
Re:Resigning as Asahi Linux project lead by joshkel on Thursday February 13, 2025 @12:48PM (#43038895)
In practice, C has a couple of significant pitfalls that I've read about.

First is if you compile with `-Werror -Wall` or similar; new compiler diagnostics can result in a build failing. That's easy enough to work around.

Second, nearly any decent-sized C program has undefined behavior, and new compilers may change their handling of undefined behavior. (E.g., they may add new optimizations that detect and exploit undefined behavior that was previously benign.) See, e.g., this post by cryptologist Daniel J. Bernstein: https://groups.google.com/g/boring-crypto/c/48qa1kWignU/m/o8...

Re:Resigning as Asahi Linux project lead by yaro330 on Thursday February 13, 2025 @01:13PM (#43039238)
The warning argument is silly. It just means that your code is not up to par with the modern standards. -Wall is a moving goalpost and it's getting new warnings added with every release of a TC because TC developers are trying to make your code more secure.
Re:Resigning as Asahi Linux project lead by joshkel on Thursday February 13, 2025 @02:40PM (#43040329)
I mean, yeah, I said it was easy enough to work around. But it's an issue I've seen raised in a discussions of C code maintenance. (The typical conclusion is that using `-Wall -Werror` is a mistake for long-lived, not-actively-developed code.) Apologies if I overstated the case.
Re:Resigning as Asahi Linux project lead by uecker on Thursday February 13, 2025 @12:59PM (#43039037)
Why not entirely wrong, the UB issues are bit exaggerated in my opinion. My C code from 20 years ago still works fine even when using modern compilers. In any case, our plan is to remove most of UB and there is quite good progress. Complaining that your build fails with -Werror seems a bit weird. If you do not want it, why explicitly request this with -Werror?
Re:Resigning as Asahi Linux project lead by nindalf on Thursday February 13, 2025 @01:06PM (#43039150)
Just curious, when you’re done removing all the UB, how will you know you’ve been successful? UB is hard to find isn’t it?
Re:Resigning as Asahi Linux project lead by uecker on Thursday February 13, 2025 @01:11PM (#43039194)
To be clear: I mean UB in the C standard. The cases where there is UB are mostly spelled out explicitly, so we can go through all the cases and define behavior. There might be cases where there is implicit UB, i.e. something is accidentally not specified, but this has always been fixed when noticed. It is not possible to remove all cases of UB though, but the plan is to add a memory safe mode where there is no UB similar to Rust.
Re:Resigning as Asahi Linux project lead by steveklabnik on Thursday February 13, 2025 @01:13PM (#43039228)
gets() was straight-up removed in C11.

Every language has breaking changes. The question is the frequency, not if it happens at all.

The C and C++ folks try very hard to minimize breakage, and so do the Rust folks. Rust is far closer to those two than other languages. I'm not willing to say that it's the same, because I do not know how to quantify it.

Re:Resigning as Asahi Linux project lead by cornstalks on Thursday February 13, 2025 @01:56PM (#43039749)
But you can still use gets() if you're using C89 or C99[1], so backwards compatibility is maintained.

Rust 2015 can still evolve (either by language changes or by std/core changes) and packages can be broken by simply upgrading the compiler version even if they're still targeting Rust 2015. There's a whole RFC[2] on what is and isn't considered a breaking change.

[1]: https://gcc.godbolt.org/z/5jb1hMbrx

[2]: https://rust-lang.github.io/rfcs/1105-api-evolution.html

Re:Resigning as Asahi Linux project lead by steveklabnik on Thursday February 13, 2025 @02:07PM (#43039895)
> so backwards compatibility is maintained.

That's not what backwards compatibility means in this context. You're talking about how a compiler is backwards compatible. We're talking about the language itself, and upgrading from one versions of the language to the next.

Rust 2015 is not the same thing as C89, that is true.

> packages can be broken by simply upgrading the compiler version

This is theoretically true, but in practice, this rarely happens. Take the certainly-a-huge-mistake time issue discussed above. I actually got hit by that one, and it took me like ten minutes to even realize that it was the compiler's fault, because upgrading is generally so hassle free. The fix was also about five minutes worth of work. Yes, they should do better, but I find Rust upgrades to be the smoothest of any ecosystem I've ever dealt with, including C and C++ compilers.

Re:Resigning as Asahi Linux project lead by cornstalks on Thursday February 13, 2025 @02:29PM (#43040197)
(side note: I don't think I've ever thanked you for your many contributions to the Rust ecosystem, so let me do that now: thank you!)

> You're talking about how a compiler is backwards compatible. We're talking about the language itself, and upgrading from one versions of the language to the next.

That's part of the problem. Rust doesn't have a spec. The compiler is the spec. So I don't think we can separate the two in a meaningful way.

Re:Resigning as Asahi Linux project lead by steveklabnik on Thursday February 13, 2025 @02:41PM (#43040337)
You're welcome!

> So I don't think we can separate the two in a meaningful way.

I think that in that case, you'd compare like with like, upgrading both.

I do agree that gcc and clang supporting older specs with a flag is a great feature, and is something that Rust cannot do right now.

But the results of the annual survey have come out: https://blog.rust-lang.org/2025/02/13/2024-State-Of-Rust-Sur...

And 90% of users use the current stable version for development. 7.8% use a specific stable released within the past year.

These numbers are only so high because it is such a small hassle to update even large Rust codebases between releases.

So yes, in theory, breakage can happen. But that's in theory. In practice, this isn't a thing that happens very much.

Re:Resigning as Asahi Linux project lead by kibwen on Thursday February 13, 2025 @01:53PM (#43039709)
Not even close to 100%, the reason that it feels like every major C codebase in industry is pinned to some ancient compiler version is because upgrading to a new toolchain is fraught. The fact that most Rust users are successfully tracking relatively recent versions of the toolchain is a testament to how stable Rust actually is in practice (an upgrade might take you a few minutes per million lines of code).
Re:Resigning as Asahi Linux project lead by umanwizard on Thursday February 13, 2025 @09:02PM (#43043891)
IDK about "industry" but I can't think of any prominent C or C++ open-source codebase that requires a specific version of gcc or clang to compile.
Re:Resigning as Asahi Linux project lead by dralley on Thursday February 13, 2025 @09:46PM (#43044201)
The Linux kernel was that way for a while, years ago.
Re:Resigning as Asahi Linux project lead by dezgeg on Friday February 14, 2025 @03:24AM (#43046138)
Try following your favourite distro's bug tracker during GCC upgrade. Practically every update breaks some packages, sometimes less, sometimes more (esp. when GCC changes their default flags).

Here's one example of workarounds in ~100 packages that broke when upgrading to GCC 10: https://github.com/search?q=repo%3ANixOS%2Fnixpkgs%20fcommon...

Re:Resigning as Asahi Linux project lead by o11c on Thursday February 13, 2025 @06:04PM (#43042616)
C (and C++) code breaks all the time between toolchain versions (I say "toolchain" to include compiler, assembler, linker, libc, etc.). Some common concerns are: headers that include other headers, internal-but-public-looking names, macros that don't work the way people think they do, unusual function-argument combinations, ...

Decades-old codebases tend to work because the toolchain explicitly hard-codes support for the ways they make assumptions not provided by any standard.

Re:Resigning as Asahi Linux project lead by gkbrk on Thursday February 13, 2025 @12:15PM (#43038429)
The backwards compatibility guarantee for C is "C99 compilers can compile C99 code". If they can't, that's a compiler bug. Same for other C standards.

Since Rust doesn't have a standard, the guarantee is "whatever the current version of the compiler can compile". To check if they broke anything they compile everything on crates.io (called a crater run).

But if you check results of crater runs, almost every release some crates that compiled in the previous version stop compiling in the new version. But as long as the number of such breakages it not too large, they say "nothing is broken" and push the release.

Re:Resigning as Asahi Linux project lead by purplesyringa on Thursday February 13, 2025 @12:34PM (#43038720)
Can you provide an example for the broken-crater claim? As far as I'm aware, Rust folks don't break compatibility that easily, and the one time that happened recently (an old version of the `time` crate getting broken by a compiler update), there were a lot of foul words thrown around and the maintainers learned their lesson. Are you sure you aren't talking about crates triggering UB or crates with unreliable tests that were broken anyway?
Re:Resigning as Asahi Linux project lead by uecker on Thursday February 13, 2025 @01:21PM (#43039320)
I am not following this too closely (the time issue seemed pretty severe though), but there are compatibility changes listed in the release notes very frequently: https://github.com/rust-lang/rust/blob/master/RELEASES.md
Re:Resigning as Asahi Linux project lead by knowitnone on Thursday February 13, 2025 @12:59PM (#43039038)
What do you mean? Rust 1.0 can compile Rust 1.0. Rust 1.1 can compile Rust 1.1.
Re:Resigning as Asahi Linux project lead by chongli on Thursday February 13, 2025 @02:01PM (#43039808)
C makes a distinction between the language version and the compiler version. Rust does not. That's the problem people are discussing here.
Re:Resigning as Asahi Linux project lead by gkbrk on Thursday February 13, 2025 @01:20PM (#43039311)
C99 isn't a compiler version. It's a standard. Many versions of GCC, Clang and other compilers can compile C99 code. If you update your compiler from gcc 14.1 to gcc 14.2, both versions can still compile standard code.
Re:Resigning as Asahi Linux project lead by uecker on Thursday February 13, 2025 @01:24PM (#43039356)
There is also a very high level of backwards compatibility between versions of ISO C because there is a gigantic amount of code is updated if there is change. So such changes are done only for important reasons or after a very long deprecation period.
Re:Resigning as Asahi Linux project lead by umanwizard on Thursday February 13, 2025 @01:13PM (#43039231)
Right, which is basically the opposite of what backwards incompatibility means. Imagine if GCC 14.2.0 was only guaranteed to be able to compile "C 14.2.0".
Re:Resigning as Asahi Linux project lead by johnisgood on Thursday February 13, 2025 @01:34PM (#43039471)
But Rust 1.0 can't compile Rust 1.1.

And as others have noted, C99 is a standard and Rust lacks one.

Re:Resigning as Asahi Linux project lead by tremon on Thursday February 13, 2025 @01:40PM (#43039542)
But Rust 1.0 can't compile Rust 1.1

That's an impossible standard to hold Rust to, did you mean it the other way around? A C89 compiler can't compile all of C99 either.

Re:Resigning as Asahi Linux project lead by gkbrk on Thursday February 13, 2025 @01:47PM (#43039640)
But v1 of a C99 compiler can compile all of C99, and v2 of a C99 compiler can still compile all of C99.
Re:Resigning as Asahi Linux project lead by p_l on Thursday February 13, 2025 @01:02PM (#43039076)
For the purposes of linux kernel, there's essentially a custom superset of C that is defined as "right" for linux kernel, and there are maintainers responsible for maintaining it.

While GCC with few basic flag will, in general, produce binary that cooperates with kernel, kbuild does load all those flags for a reason.

Re:Resigning as Asahi Linux project lead by CRConrad on Tuesday February 18, 2025 @01:40PM (#43093439)
> For the purposes of linux kernel, there's essentially a custom superset of C that is defined as "right" for linux kernel

Superset? Or subset? I'd have guessed the latter.

Re:Resigning as Asahi Linux project lead by p_l on Wednesday February 19, 2025 @02:49PM (#43106625)
Superset. ANSI/ISO C is not a good language to write a kernel in, because the standards are way more limiting than some people would think - and leaves a lot to implementation.

So it's a superset in terms of what's defined