memoffset
memoffset copied to clipboard
offset_of! for unsized structs
This doesn't work with memoffset:
struct Foo {
bar: f32,
baz: [f32],
}
offset_of!(Foo, bar);
Even though this (unsound) code works:
struct Foo {
bar: f32,
baz: [f32],
}
let foo_ptr: &Foo = unsafe { mem::zeroed() };
let foo_offs = (&foo_ptr.bar) as *const _ as usize;
I ran into this problem when trying to port glium to memoffset in https://github.com/glium/glium/pull/1782. The gpgpu example has relied on offset of calculations supporting unsized structs. I could work around the issue by changing the gpgpu example, but that isn't really perfect.