Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A lot of things that C will let you do (even if you enter the realm of undefined behaviour) will simply not compile to C. As the author states, there are semantic differences between pointers and Rust's references.

C pointers can have as many owners as you want, may be subjected to mathematical operations, and can be cast to any type without even an error message. The compiler will just assume you know what you're doing. If you enable enough compiler warnings, it might warn you, but C compilers don't generate a lot of those by default.

Rust will let you only generate one mutable (exclusive) reference at a time. This means straight C to Rust ports simply don't compile.

By switching to pointers, which work pretty much like their C equivalent, you can port the code much easier, but you do of course lose the benefits of Rust's safety mechanisms, because most pointer operations throw away all the safety guarantee that Rust provides.



> Rust will let you only generate one mutable (exclusive) reference at a time.

Safe Rust includes many forms of shared mutability, including Cell<> which is perhaps the closest comparison to typical patterns in C code.


So what is the advantage of an unsafe Rust implementation? Just to have done it?


It is rewritten to a different language and many people find Rust easier to read, it has better type hint support for IDE etc. Also, you do not lose all the safety, there are still many rules enforced, such as safe linking, no undefined functions. Unsafe Rust means that all parts of code which do illegal pointer magic are explicitly marked with an "unsafe" keyword. You can now go one by one and fix them.


[flagged]


> chuckles

jesus christ, you’re not light yagami—please stay on /g/


Someone is going on a witch-hunt. Most of my comments under this submission are flagged, including this one: https://news.ycombinator.com/item?id=44464177.

Crazy. They have gotten quite a lot of upvotes, for the record, but feel free to flag ALL of my comments.

I wonder what is so wrong about asking if I cannot chuckle anymore, so wrong that it warrants it to be flagged.

>> chuckles (written by me)

> jesus christ, you’re not light yagami—please stay on /g/ (written by some individual)

However, is not flagged. It would be hilarious if it was not so sad.


Once the codebase is all Rust you can start introducing Rust idioms and patterns. Basically step 1 is to get it working in Rust then step 2 is to clean up the Rust to actually take advantage of the language.


From the article: "The next goal is to convert the codebase to safe Rust."


In addition to other points about making it progressively safe, unsafe Rust is still safer than C. https://bsky.app/profile/ssg.dev/post/3lkjogvm2c222


Rust is like walking across a mine field with all the mines flagged for you. You can dig up the mine and remove the flags over time. Or at least know to avoid stepping carelessly around them.

In C you only see the flags people know of or remembered to plant. There's an awful lot of mines left unflagged and sometimes you step on them.

It's very obvious to me which would be more safe and I find myself questioning why it is isn't so obvious to others.


Hmm...I like when the compiler don't steps in my way and assumes that I know what I'm doing. Thats the reason why I don't like Rust. But when you like it, have fun!


"Hmm...I like when the assembler don't steps in my way and assumes that I know what I'm doing. Thats the reason why I don't like C, and prefer assembler. But when you like it, have fun!"


C code is shorter than both assembly and Rust, it's not the same thing.


Both rust and C are also much, much less error-prone than assembly. It is so, so easy to get things wrong in assembly in very subtle ways. That’s one of the main drivers while people are only writing assembly today when they absolutely have to.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: