blob: 7b79f309b027b577d2b7e927b83ba94e04de2578 [file] [log] [blame]
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]
#![no_std]
mod libc {
pub type c_int = i32;
pub enum c_void {}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct foo {
pub a: libc::c_int,
pub b: libc::c_int,
pub bar: *mut libc::c_void,
}
#[test]
fn bindgen_test_layout_foo() {
assert_eq!(
::core::mem::size_of::<foo>(),
16usize,
concat!("Size of: ", stringify!(foo))
);
assert_eq!(
::core::mem::align_of::<foo>(),
8usize,
concat!("Alignment of ", stringify!(foo))
);
assert_eq!(
{
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
let struct_ptr = &struct_instance as *const foo;
let field_ptr = core::ptr::addr_of!(struct_instance.a);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
core::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
0usize,
concat!("Offset of field: ", stringify!(foo), "::", stringify!(a))
);
assert_eq!(
{
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
let struct_ptr = &struct_instance as *const foo;
let field_ptr = core::ptr::addr_of!(struct_instance.b);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
core::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
4usize,
concat!("Offset of field: ", stringify!(foo), "::", stringify!(b))
);
assert_eq!(
{
let struct_instance = unsafe { core::mem::zeroed::<foo>() };
let struct_ptr = &struct_instance as *const foo;
let field_ptr = core::ptr::addr_of!(struct_instance.bar);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
core::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
8usize,
concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar))
);
}
impl Default for foo {
fn default() -> Self {
let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
unsafe {
::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}