Search
 
SCRIPT & CODE EXAMPLE
 

RUST

armanriazi•rust•unsafe•rawpointer

Unsafe Rust has two new types called raw pointers that are similar to references. As with references, raw pointers can be immutable or mutable and are written as *const T and *mut T, respectively. The asterisk isn’t the dereference operator; it’s part of the type name. In the context of raw pointers, immutable means that the pointer can’t be directly assigned to after being dereferenced.
    let mut num = 5;
    let r1 = &num as *const i32;
    let r2 = &mut num as *mut i32;
Notice that we don’t include the unsafe keyword in this code. We can create raw pointers in safe code; we just can’t dereference raw pointers outside an unsafe block, as you’ll see in a bit.    
    unsafe {
        println!("r1 is: {}", *r1);
        println!("r2 is: {}", *r2);
    }

   let address = 0x012345usize;
   let r = address as *const i32;
   
Creating a raw pointer to an arbitrary memory address
Comment

PREVIOUS NEXT
Code Example
Rust :: How to pass a string literal 
Rust :: armanriazi•rust•error•[E0106]: missing lifetime specifier -- src/main.rs:5:16 | 5 | fn dangle() - &String { | ^ expected named lifetime parameter 
Rust :: sort reverse rust 
Rust :: rust•armanriazi•trait 
Rust :: Find the next smaller positive integer containing the same digits 
Rust :: rust spinning rod animation in text 
Rust :: armanriazi•rust•collection•hashmap•avoid_of_duplicate 
Rust :: rust comments 
Rust :: rust absolute path 
Rust :: rust program name 
Rust :: rust sort vec of f64 
Rust :: armanriazi•rust•trait•external•implement•coherence•orphan 
Rust :: armanriazi•rust•trait•object•safe 
Rust :: armanriazi•rust•error•already borrowed: BorrowMutError 
Lua :: roblox for children loop 
Lua :: how to choose a random item from a table lua 
Lua :: roblox make kill brick 
Lua :: roblox how to loop through all players 
Lua :: roblox how to find value in table 
Lua :: for i in pairs lua 
Lua :: lua json decode 
Lua :: lua print 
Lua :: how to make a welcome badge roblox lua 
Lua :: how to make variables in lua 
Lua :: unsur unsur hidrogen 
Lua :: how to check if table is clear 
Matlab :: save mat file script in matlab directory 
Matlab :: display sequence in matlab 
Basic :: how to send basic auth using fetch 
Basic :: dos assign command output to variable (when output is of multiple lines) 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =