Skip to content

Instantly share code, notes, and snippets.

@hadronized
Last active March 20, 2017 00:08
Show Gist options
  • Save hadronized/1fc7534cd08e4fe55a926ab262593144 to your computer and use it in GitHub Desktop.
Save hadronized/1fc7534cd08e4fe55a926ab262593144 to your computer and use it in GitHub Desktop.
// Without compiling nor running the following program, what do you expect its output to be? :)
// Have a great monday!
fn main() {
let mut a: u16 = 42;
let b: u16 = 7;
println!("before, a: {}\tb: {}", a, b);
unsafe { foo(&mut a as *mut u16 as *mut u32); }
println!("after, a: {}\tb: {}", a, b);
}
unsafe fn foo(a: *mut u32) {
*a = (42 << 16) + 7;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment