1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-12-23 23:12:52 +02:00
Files
comprehensive-rust/src/unsafe/extern-functions.md
2022-12-21 16:38:28 +01:00

344 B

Calling External Code

Functions from other languages might violate the guarantees of Rust. Calling them is thus unsafe:

extern "C" {
    fn abs(input: i32) -> i32;
}

fn main() {
    unsafe {
        // Undefined behavior if abs misbehaves.
        println!("Absolute value of -3 according to C: {}", abs(-3));
    }
}