Skip to content

Instantly share code, notes, and snippets.

@jld
Created February 10, 2013 07:37
Show Gist options
  • Select an option

  • Save jld/4748798 to your computer and use it in GitHub Desktop.

Select an option

Save jld/4748798 to your computer and use it in GitHub Desktop.
Alignment is hard.
enum NewType<T> = T;
struct UnAligned<T> { a: u8, b: T }
fn main() {
unsafe {
let p: *UnAligned<u32> = ptr::null();
io::println(fmt!("%?", ptr::addr_of(&(*p).b) as uint));
}
unsafe {
let p: *UnAligned<NewType<u32>> = ptr::null();
io::println(fmt!("%?", ptr::addr_of(&(*p).b) as uint));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment