You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Rust, the #[repr(packed)] attribute is intended to remove padding between struct fields. Similarly, #[repr(align(n))] is used to adjust the alignment of a struct to n bytes. However, in the case of gccrs, it appears that these attributes are not fully respected.
// uncomment commented code to run with gccrs// #![feature(intrinsics)]// #[lang = "sized"]// pub trait Sized {}// extern "rust-intrinsic" {// fn size_of<T>() -> usize;// }extern"C"{fnprintf(format:*consti8, ...);}#[repr(packed)]structStructPacked{flag:bool,number:i32,data:[u8;16],}#[repr(align(16))]structStructAligned{flag:bool,number:i32,data:[u8;16],}fnmain(){let matrix = [[1.0;4];4];let data = [0u8;16];let struct_packed = StructPacked{flag:true,number:42,
data,};let struct_aligned = StructAligned{flag:true,number:42,
data,};println!("StructPacked: {}", size_of::<StructPacked>());println!("StructAligned: {}", size_of::<StructAligned>());// uncomment below for gccrs// unsafe{// printf(// "StructPacked: %zu\n\0" as *const str as *const i8,// size_of::<StructPacked>(),// );// printf(// "StructAligned: %zu\n\0" as *const str as *const i8,// size_of::<StructAligned>(),// );// }}
In Rust, the #[repr(packed)] attribute is intended to remove padding between struct fields. Similarly, #[repr(align(n))] is used to adjust the alignment of a struct to n bytes. However, in the case of gccrs, it appears that these attributes are not fully respected.
rustc:
gccrs:
godbolt: https://godbolt.org/z/rornPra3c
The text was updated successfully, but these errors were encountered: