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 :: armanriazi•rust•thread•spawning•join 
Rust :: armanriazi•rust•oop 
Rust :: armanriazi•rust•mem•leak 
Rust :: armanriazi•rust•type•wrapper•vs•clone 
Rust :: $sce trust url 
Rust :: rust•armanriazi•error•[E0277]: `Rc<Mutex<i32` cannot be sent between threads safely `Rc<Mutex<i32` cannot be sent between threads safely 
Rust :: rust•armanriazi•type•wraper 
Rust :: rust sort vec of f64 
Rust :: rust•armanriazi•modified•data•by•compiler•cast•number•i32•to•u8 
Rust :: armanriazi•rust•thread•rayon•join•workstealing 
Rust :: armanriazi•rust•refactor•flowcontrol•match•unwrap_or_else 
Rust :: armanriazi•rust•concept•coherence 
Lua :: how to disable animations roblox 
Lua :: lua not equal 
Lua :: lua round number 
Lua :: roblox tween color part 
Lua :: lua for loop 
Lua :: lua click button 
Lua :: lua event 
Lua :: for loop roblox 
Lua :: datastore roblox 
Lua :: What is The Color changing script for luaa 
Lua :: svelte template vite 
Lua :: lua scp 914 card script 
Lua :: table.move lua 
Matlab :: find location of max value in array matlab 
Matlab :: tan in scilab 
Basic :: how to add basic authentication on haproxy backend server 
Basic :: fill in the commands belllow if you wanted to map a value saved in the variable count from one tange to another 
Elixir :: elixir map to new map 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =