If I do this struct
#[repr(C)]
struct Thing {
f1: u128
f2: u32
}
Then I get a size of 32 and an alignment of 16.
Why isn’t it just 20 bytes and how can I fix it so it is?
The context is I’m trying to build a struct to represent MMIO data so I need things to be in the right position.
I just tried repr(packed) instead. That seems to work but the docs seems to discourage its use.
Anthony McCann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
The answer was not repr(packed), that did get the size looking right but it just leads to immediate alignment issues.
Solution was to use repr(C), but just go back through my piles of structs and figure out where things were getting misplaced.
Anthony McCann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.