Can I turn off zero division checking every time division occurs?

To better understand Rusts panic / exclusion mechanisms, I wrote the following code fragment:

#![feature(libc)]

extern crate libc;

fn main() {
    let mut x: i32;
    unsafe {
      x = libc::getchar();
    }

    let y = x - 65;
    println!("{}", x);

    let z = 1 / y;
    println!("{}", z);
}

I wanted to check how Rust works with division by zero cases. Initially, I assumed that he either took the raw SIGFPE in person, or died, or implemented a handler and redirected it to panic (which can be dealt with now?).

The code is verbose because I wanted to make sure that Rust wasn’t doing anything β€œsmart” when, at compile time, it knew that something was null, hence user input. Just give him an β€œA,” and he should do the trick.

, Rust , , . .: -)

: ? , . ? SIGFPE?

Github, .

, " ". ? - ?

+6
1

, " ". ?

?

- ; , , , .

, : ?

0 , , , , 0. , , - .

, :

  • ,
  • .

, . , ~ 100 1 , ( ).

1 . Agner Fog: , Intel Nehalem DIV IDIV 64- 28 90 37 100 .


, rustc LLVM, . , rustc LLVM , .

LLVM : udiv sdiv.

Undefined 0.

Rust ​​ Undefined, 0, .

, LLVM.

+5

Source: https://habr.com/ru/post/1015388/


All Articles