typedef union __declspec(align(16)) TestUnion
{
unsigned long Longs[2];
unsigned int Ints[4];
} TestUnion;
bindgen .\test.h -o test.rs
#[repr(C)]
#[repr(align(16))]
#[derive(Copy, Clone)]
pub union TestUnion {
pub Longs: [::std::os::raw::c_ulong; 2usize],
pub Ints: [::std::os::raw::c_uint; 4usize],
_bindgen_union_align: u128,
}
I believe the u128 member of the union is unnessecary and actually triggers a warning (improper_ctypes) as u128s are not stable across the FFI boundary. My understanding here is that #[repr(align(16))] is sufficient to ensure the correct alignment for this union.
You're right. This should be trivial to fix. Relevant code is:
@emilio Would this be the desired behavior?
#[repr(align(n))]. Do not add fields to the struct.u128). Do not use #[repr(align(n))]Yes, that's right, though it's even simpler, given support for repr(align) predates support for u128 / i128. So we should just not generate that alignment field if repr(align) is supported, and add a test.