SHARE
TWEET

Untitled

a guest Jul 17th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct A {
  2.     a: i32,
  3.     b: i32
  4. }
  5.  
  6. struct B {
  7.     c: i32,
  8.     suba: A
  9. }
  10.  
  11. fn modify(v: *mut B) {
  12.     unsafe {
  13.         (*v).suba.b += 20;
  14.     }
  15. }
  16.  
  17. fn main() {
  18.     let mut v = B { c: 10, suba: A { a: 5, b: 2 }};
  19.     //println!("v.a {}, v.b {}", v.a, v.b);
  20.     let rp = &mut v as *mut B;
  21.     let subb = &v.suba.b as *const i32;
  22.     modify(rp);
  23.     println!("rp.suba.b {}, subb {}, v.suba.b {}", unsafe { (*rp).suba.b }, unsafe { (*subb) }, v.suba.b);
  24. }
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