const t2 = packed struct {
v1: u32,
v2: u32,
v3: u32,
v4: u32,
v5: u32,
v6: u32,
v7: u32,
v8: u32,
v9: u32,
v10: u32,
};
const t1 = struct {
v1: u32,
v2: u32,
v3: u32,
v4: u32,
v5: u32,
v6: u32,
v7: u32,
v8: u32,
v9: u32,
v10: u32,
};
sizeof(t1) is 40
sizeof(t2) is 48
I am a bit confused why it is larger?
I saw a few other posts about odd sizing of packed structs which seemed related to odd sized number of bytes / bits 40 is already an even number
I saw there is extern struct which just ends up being the same size as the normal struct in my case (which im not sure what its supposed to do)
The reason for this is similar to the other posts I have seen. I have some []u8
(byte array) which I want to @ptrCast
into a struct (compiler also wants @alignCast
so I added that as well) is there a easy way to do this in zig? which can be somewhat common in c. I would honestly prefer if I didnt have to make it packed but I assume there is not an easy way around that and I want to take the easy path right now rather than parsing a bunch of numbers from a byte array
Should I cast into a u32 array first then into the struct?