“Armanriazirustunsafestatic” Code-Antworten

Armanriazirustunsafestatic

Until now, we’ve not talked about global variables, which Rust does support but can be problematic with Rust’s ownership rules. If two threads are accessing the same mutable global variable, it can cause a data race.
'static lifetime, which means the Rust compiler can figure out the lifetime and we aren’t required to annotate it explicitly. Accessing an immutable static variable is safe.
ArmanRiazi

ARMANRIAZIRUSTUNSAFEEXTERTE

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

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen