Hacker News

Favorites Setup
Comment by skydhash | original | C for Rust programmers
[−]skydhash · 2026-10-10 Sat 15:36 UTC · link
> But, in 2026, I don't see why for native code everyone shouldn't be programming in Rust / Swift / other modern memory-safe flavor for any new production use. Zig if you want faster compile times, I guess.

Because C is very simple (unlike Rust) and works everywhere. Zig is not yet stable. Go and Swift are under the governance of tech companies.

The true appeal of C for me is the standard and how it applies only to the language. You can easily take a project from 2 decades ago and port it to a current platform. Lot of current ecosystem is way too fussy about tooling to do this.

[−]tialaramex · 2026-10-10 Sat 20:23 UTC · link
> Because C is very simple (unlike Rust) and works everywhere

That's definitely true. C is a "Worse is better" language and as such it's everywhere. You can knock together a halfway usable C for some crap hardware in a few weeks and then the hardware is saleable because there's a C implementation.

> You can easily take a project from 2 decades ago and port it to a current platform.

Much of the software I wrote two decades ago in C won't even build today. Good luck figuring out why, periodically I try to figure out which weird 2000s era Mac OS hacks don't like a 2026 Linux system and eventually I give up and write modern software instead.

In theory C written in 2006 definitely "just works" on a 2026 Linux machine but in practice real world C is broken and even though I (co)wrote it I don't know why. Also in practice the first serious Rust project I wrote in 2021 I just found it, checked out the oldest working version ("first rough working code" says the log) from git, cargo run, works as expected.

Maybe it's because the C was four times older, but I think it's because in the real world you don't end up writing that mythical portable C code too often.

[−]fastaguy88 · 2026-10-11 Sun 01:55 UTC · link
I have 'C' code that was written in 1985 that runs today, mostly after moving function parameters from inside the function to inside the argument list.

'C' seems to be a language that makes it easy to write incomprehensible statements, but it's not that hard (or it was not that hard) to write code that is trivial bring up to date. Perhaps it was easier for me because I started with Fortran.

[−]fithisux · 2026-10-11 Sun 05:16 UTC · link
Very common.
[−]msla · 2026-10-11 Sun 08:04 UTC · link
I will never understand why some people put C in quotes.

Do you also put Java in quotes? Rust?

[−]pjmlp · 2026-10-11 Sun 09:52 UTC · link
Only if it targeted UNIX in first place, or was only making use of standard library.

I am quite sure my MS-DOS C code is going to have some hard time being compiled on GCC 16.

[−]lelanthran · 2026-10-11 Sun 05:56 UTC · link
> Maybe it's because the C was four times older, but I think it's because in the real world you don't end up writing that mythical portable C code too often.

It's because C, over time, went from a bunch of almost compatible implementations, to a standard that differed a little from every existing implementation, to a standard that is updated every decade or so, which is then implemented by a bunch of different products, with enough ambiguity in the standard (UB) that there will be differences between compilers and versions of compilers.

Rust is a single implementation. Always has been.

It's a single product, so you code to the product. The product has no external forcing function, like a language standard, that produces changes every decade. When you write Rust, you aren't thinking "Wait, lets make sure this works on the Watcom compiler too".

If Rust code cannot compile 30 years later, that's a failure on the language, because the single implementation is in full control of compatibility. If C code cannot compile 30 years later, that's not a failure of the language, because the implementation in 30 years has had external pressure forcing changes.

People often forget that Rust is a product, C is a specification.

[−]tialaramex · 2026-10-11 Sun 09:00 UTC · link
> a standard that is updated every decade or so

In practice the cadence is exactly half that of WG21's breakneck C++ pace. Every six years. C11, C17, C23 so far and C2y is expected to land before the end of this decade.

But anyway, all I can do is report the observable fact. If you want to say it's because GCC 15 is a different product from GCC 4 whereas rustc 1.99 is the same product as rustc 1.49 then I guess you can re-phrase my position as "In C you will keep needing new products and that sucks" if you like.

[−]pjmlp · 2026-10-11 Sun 09:50 UTC · link
In theory, in practice many C developers only know "My C Compiler standard", and are usually surprised that some of their expectations aren't even part of ISO C PDF specification.

Then they get irritated that not all C compiler vendors have the same language extensions or implementation defined behaviours they got used to rely on.

[−]jstimpfle · 2026-10-11 Sun 10:34 UTC · link
True. In C, it's hard to know what's defined where and what dependencies one is even using unknowingly. The only help is to build on multiple platforms from early on, this will reduce the pain of porting to new platforms later.
[−]jstimpfle · 2026-10-11 Sun 09:03 UTC · link
It's _very_ easy to write C that is impossible to port to other platforms or other compilers. The reason is that more than for most other ecosystems, there are many different implementations with their own implementations and quirks.

It's also easy to write C that won't build on the system it was originally developed on, a few years down the line. But that is true for almost every other language ecosystem. I would say, C makes it _possible_ to write code in such a way that it works on many different platforms and compilers, and/or can continue to work in decades to come with relatively little maintenance.

The latter isn't true for most other ecosystems, because to get anything done in them, you need to rely more on that language and its ecosystem -- specific language features, specific libraries. C isn't a glue code language. It's very good at letting you create your own thing.

To do it well though, requires a lot of care and expertise.

[−]creata · 2026-10-11 Sun 09:22 UTC · link
> more than for most other ecosystems, there are many different implementations with their own implementations and quirks.

Is that the reason? I thought it was primarily because C stupidly* makes a ton of platform-specific things more convenient than the platform-independent equivalent - the width of integer types, locales, etc., all vary by platform, and it's easy to accidentally depend on them.

* Maybe it wasn't stupid at the time when C was developed, but it's a bad choice now.

[−]jstimpfle · 2026-10-11 Sun 10:31 UTC · link
Integer widths are a problem, but hardly the biggest headache (unless it's a decade old preexisting project that was never designed with portability in mind). Fixed width integer types like int32_t have existed for decades. Even Rust has usize which is machine dependent, and pointers as well have to be machine dependent of course.

Much bigger problem is understanding the scope of dependencies. Dependencies can go bad and you need to update. A dependency might not be available on some new platform so you might have to replace with something else on that platform. To make the software portable, good modularity is required. This is to a large extent an aspect of software architecture. Even Rust can't magically make this happen, if you depend on 300 crates that's probably not a great place to be in either if you want to be portable and maintainable.

There is probably a point that C's flat namespace is a major contributor to badly designed software, because people aren't aware of the dependencies they're mixing all the time. Also C encourages transitive includes, leaking implementation details to the user instead of just to the compiler. (But btw. I find C++ and Rust namespace to be unergonomic syntax-wise, and what's needed is not actually namespaces but control over visibility).