HACKER Q&A
📣 rommidnight

Why C’s compiler is not as smart as Rust’s


I get that language syntax and explicit keywords is a must for smart compiler but how come there is no something good that enables C safety in compile time? Like adding some custom keywords while maintaining compatibility with bare C? Logically, there would be an attempt at this of which I am not aware, but still, how did it not become massive enough(relatively to Rust, how it gained popularity with safety + performance) This question is not aimed at roots of C but why it did not evolve in this direction. I was wondering, is there a flavor of C which guarantees safety, and if there is, why is not it as popular as rust

Update: also, what would be main problem in taking goodness of rust and putting it in C’s new compiler


  👤 gostsamo Accepted Answer ✓
The very short answer is that rust achieves what it does with lots of resources eaten by the compiler and with lots of constrains. C was created and got popular in the times when resources were cut and even the constrains the language imposed were considered high-level stuff. If you think why it didn't evolve, well it actually did and we call it c++. What c++ shows is that backward compatibility with already existing code prevents lots of optimizations that rust can afford to build in from the start.

👤 viraptor
Sounds like you're thinking of a more restrictive dialect of C. These exist and Cyclone is probably the most known one: https://cyclone.thelanguage.org/

Why it's not as popular is an area for speculation, but I would guess that it just didn't provide enough value on top. Rust gives you lots more features than just extra safety, so there are more reasons to choose it.


👤 sloaken
There is, and they call it JAVA