From a technical perspective, what is preventing Rust from replacing C?

From a technical perspective, what, if anything, is preventing Rust from replacing C? Was it meant to replace C or C++, or neither? Also, while you’re here - what’s the fastest and easiest way to port Rust code to C code?



When you say “replacing C”, it’s important to think about what usage of C you’re intending to cover. C is used for many different reasons, and you certainly can’t satisfy them all with Rust. (For instance, you’re probably never going to get Rust to compile a C++ header.)

With that said, if you’re starting a project from scratch and are wondering why you’d chose C over Rust, assuming you knew them both with an equal level of competence… you might still choose C because it has a stable ABI (and thus good FFI support with other languages), or because it compiles on different platforms. Those are probably the biggest things.

There may be some more more specialized concerns too, such as some optimizations which may not be available in Rust (another side-effect of supporting different platforms), or working in very resource constrained environments (if you needed a very lightweight compiler, that might be easier to achieve with C.)

FWIW, I don’t think this is a very useful question. I.e., it doesn’t help you make decisions. Even if Rust was meant to replace C or C++, it should not be evaluated according to its ability to do so. It is intended to replace C/C++ only for those people who prefer it to. And in any case, things are only what they are, not what they are meant to be.

1 Like

Strictly technically, it’s probably the fact that there’s only one LLVM-dependent implementation, and there are platforms on which LLVM/Rust doesn’t work (yet). But technical issues are a tiny problem compared to all the non-technical ones.


Fastest way to convert code is:

but automatic conversion is not a good way to port to or from Rust. Although Rust and C work and even look somewhat similar, the way idiomatic code is written turns out to be very different, so good C code makes lousy Rust code and vice-versa. Real port, unfortunately, requires a rewrite from scratch (or at least conversion and major refactorings).

1 Like

Aah OK thanks.

I was going for more “how can I convert rust to C by hand, rewriting it in a (mostly) idiomatic way”. More like a systematic checklist to go through.