NonWonderDog [he/him]

  • 0 Posts
  • 2 Comments
Joined 6 years ago
cake
Cake day: July 26th, 2020

help-circle
  • But functioning C code is as good as functioning Rust code right?

    Practically yes, but also no. The C pointer aliasing rules limit the optimizations the compiler can apply, since any int * might point to any int in scope. It’s even worse than that in the Linux kernel: since it has to be compiled with -fno-strict-aliasing, the compiler has to assume that any pointer can alias any variable in scope.

    In contrast, Rust simply disallows aliases to mutable variables and the compiler prevents them in safe code (you can write them in unsafe code but it’s instantly undefined behavior, which is why unsafe Rust is harder to write than C). Every variable that can change has one and only one name. This can sometimes allow the Rust compiler to optimize in ways that wouldn’t be possible in C.

    But in practice the impact of this is pretty close to nil as long as you write smallish functions.