ArmanRiazirustunSafeExtern
Functions declared within extern blocks are always unsafe to call from Rust code.
The reason is that other languages don’t enforce Rust’s rules and guarantees, and Rust can’t check them, so responsibility falls on the programmer to ensure safety.
he "C" part defines which application binary interface (ABI) the external function uses: the ABI defines how to call the function at the assembly level.
extern "C" {
fn abs(input: i32) -> i32;
}
fn main() {
unsafe {
println!("Absolute value of -3 according to C: {}", abs(-3));
}
}
ArmanRiazi