SHARE
TWEET

Untitled

a guest Oct 10th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     let a=4u32;
  3.     let b = &a as *const u32;
  4.     let b = b as *mut u32;
  5.     unsafe {
  6.         test(&a, &mut *b);
  7.         println!("{}",*b);
  8.     }
  9. }
  10.  
  11. fn test(a:&u32, b:&mut u32)->u32{
  12.     if *a < 5 {
  13.         *b+= 20;
  14.     }//compiler assumes a variable cannot be
  15.     //aliased if it's mutable, so it puts an else
  16.     //here
  17.     if *a > 10 {
  18.         *b+=10;
  19.     }
  20.     *b //expected result: 34, actual result
  21.     // (in release) 24
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top