Topic List

Click a topic to learn more.


Term of the Moment

Google One


Look Up Another Term


Redirected from: C2Rust

Definition: Rust


An open source and widely praised programming language for developing system software and applications that are more robust and secure. Developed at Mozilla Research in the mid-2000s, Rust was released to the public in 2015, and its syntax evolved from OCaml, the Cyclone variant of C and C++. Rust is primarily known for its error handling and compiler safety checks that prevent a program from crashing. This is normally found in high-level languages, whereas Rust offers these "memory safe" features while providing low-level control like C and C++.

Microsoft Is Replacing C
Microsoft is rewriting Windows in Rust. In May 2023, the Windows 11 Insider Preview release was the first Windows software written in Rust offered to the public. See memory safe, C and programming languages.

From C to Rust
The C2Rust project enables C code to be automatically translated to Rust. Following is a C input and Rust output example. Needless to say, the output is a lot more wordy:

 C Input

 main()   {
  float fahr;
  printf("Enter Fahrenheit: ");
  scanf("%f", &fahr);
  printf("Celsius is %f\n", (fahr-32)*5/9);
          }


 Rust Translation

 #![allow(dead_code, mutable_transmutes,
 non_camel_case_types, non_snake_case,
 non_upper_case_globals, unused_assignments,
 unused_mut)]
 #![register_tool(c2rust)]
 #![feature(register_tool)]
 extern "C" {
   fn printf(_: *const libc::c_char, _: ...)
     -> libc::c_int;
   fn scanf(_: *const libc::c_char, _: ...)
     -> libc::c_int;
            }
 unsafe fn main_0() -> libc::c_int {
   let mut fahr: libc::c_float = 0.;
   printf(b"Enter Fahrenheit: \0" as *const u8 as
   *const libc::c_char);
   scanf(b"%f\0" as *const u8 as *const
    libc::c_char, &mut fahr as *mut libc::c_float);
      printf(
        b"Celsius is %f\n\0" as *const u8 as *const
        libc::c_char,
        ((fahr - 32 as libc::c_int as
        libc::c_float) * 5 as libc::c_int as
        libc::c_float
          / 9 as libc::c_int as libc::c_float)
        as libc::c_double,
            );
            return 0;
  }
 pub fn main() {
  unsafe { ::std::process::exit(main_0() as i32)
    }
  }