SHARE
TWEET

Untitled

a guest Feb 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[repr(align(16))]
  2. struct Foo {
  3.     a: u8,
  4.     b: u8
  5. }
  6.  
  7.  
  8.  
  9. fn main() {
  10.     use std::mem;
  11.    
  12.     let foo = Foo { a: 127, b: 63 };
  13.    
  14.     let foo_ptr : *const u8 = unsafe { mem::transmute(&foo) };
  15.     let a_ptr : *const u8 = unsafe { mem::transmute(&foo.a) };
  16.     let b_ptr : *const u8 = unsafe { mem::transmute(&foo.b) };
  17.    
  18.     let offset_a = (a_ptr as usize) - (foo_ptr as usize);
  19.     let offset_b = (b_ptr as usize) - (foo_ptr as usize);
  20.    
  21.     println!("a={}, b={}", offset_a, offset_b);
  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