proxmox-tools/src/lib.rs: implement offsetof

This commit is contained in:
Dietmar Maurer 2019-06-14 09:55:10 +02:00
parent b243d9664d
commit d7fbee66e3

View File

@ -2,3 +2,11 @@
pub mod io; pub mod io;
pub mod vec; pub mod vec;
/// Evaluates to the offset (in bytes) of a given member within a struct
#[macro_export]
macro_rules! offsetof {
($ty:ty, $field:ident) => {
unsafe { &(*(0 as *const $ty)).$field as *const _ as usize }
}
}