Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Description
Just like global variables and local variables support alignment, struct fields should support alignment.
The alignment of a struct should be the alignment of its most aligned member. As Zig iterates over the fields of a struct, it knows the current alignment at that position. When a field requires more alignment, padding bytes are inserted until the desired alignment is achieved. Zig currently does this incorrectly - See#1248
Related is reordering fields for better performance and memory usage (see#168)
You should also be able to set the alignment of fields in packed structs. This does 2 things:
- acts as assertions - compiler will give an error if the alignment is impossible given that the struct is packed
- determines the overall alignment of the packed struct - it will be the alignment of the most aligned field. if no field is specified to be aligned, the alignment of the packed struct will be 1.
A packed struct in an array should give a compile error if its size is not byte-aligned, or if its size is not aligned to its own alignment.