Search
 
SCRIPT & CODE EXAMPLE
 

RUST

armanriazi•rust•unsafe•extern

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));
    }
}

Comment

armanriazi•rust•unsafe•static

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.
Comment

PREVIOUS NEXT
Code Example
Rust :: rust•armanriazi•borrowchecker•borrow 
Rust :: armanriazi•rust•interior-mutability•vs•inherited-mutability 
Rust :: armanriazi•rust•reference•vs•pointer 
Rust :: hwllo world in rust 
Rust :: rust•armanriazi•lifetime•unsafe•destructor 
Rust :: armanriazi•rust•reference•dangle 
Rust :: armanriazi•rust•error•E0502•cannot borrow `s` as mutable because it is also borrowed as immutable 
Rust :: armanriazi•rust•error•[E0782]: trait objects must include the `dyn` keyword 
Rust :: rust match wildcard 
Rust :: rust-analyzer tab space 
Rust :: armanriazi•rust•borrowchecker•lifetime•struct 
Rust :: rust sum and average of number list 
Rust :: armanriazi•rust•smartpointer•box•vs•rc•vs•refcell 
Lua :: roblox check if player has gamepass 
Lua :: roblox get player from character 
Lua :: lua calculate average number 
Lua :: roblox on touch script 
Lua :: lua for loop 
Lua :: lua in pairs 
Lua :: Startswith function in lua 
Lua :: roblox check if in private server 
Lua :: how to access an index of a table lua 
Lua :: delete part on touch roblox 
Lua :: attempt to call a string value lua 
Lua :: Roblox studio increase variable when holding W 
Lua :: roblox lua scripts 
Matlab :: matlab number to string 
Matlab :: two return variables in matlab 
Basic :: watch starward ascii command 
Elixir :: elixir string to datetime 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =