daily pastebin goal
35%
SHARE
TWEET

Untitled

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