Last active
February 19, 2020 04:00
-
-
Save mikdusan/07c47650efd96fd674bae5843088e6a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packed_struct.md -- the main document is a comment because big fonts suck |
- TODO: incorporate this into doc (from IRC)
here is what it should mean if it is missing: if it is missing then the alignment of the address,
which is the address of the host integer, is @alignOf(@IntType(false, 1 * 8)), where 1
is the host integer byte count (the 1 in *align(:3:1))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
>>>> related
key comments:
»»»»
packed struct
The set of features that distinguish
packed struct
fromstruct
are:align(0)
»» whole-structure memory layout size
@sizeOf(__T)
(@bitOffset(__T, __last_field) + @bitSizeOf(__last_field))
and extended to meet alignment requirement»» whole-structure bit-size
@bitSizeOf(__T)
@bitOffsetOf(__T, __last_field) + @bitSizeOf(__last_field)
»» whole-structure alignment
@alignOf(__T)
@alignOf(__T)
@alignOf(__T) == 0 and @bitSizeOf(__T) != 0
alignment is 1»» field alignment
@fieldAlignOf(__T, __field_name)
align(0)
If necessary, layout size is padded to the next multiple of its most-aligned field's alignment.
»» field pointers
@bitOffsetOf() % 8 != 0
) have special meta-information shown as an extended alignment tuple:*align(__A:__O:__H)
__H
is the host-integer size in bytes__O
is the bit-offset from host-integer's 0-bit__A
is the host-integer alignment in bytes__A
is not explicitly shown it's value is0
__A
is shown the field is 8-bit alignedFor example, on x86_64, a
u5
field could be unaligned-from-byte by 0 to 3 bits and Zig chooses the smallest possible host-integer size which is a single byteu8
. Consider if theu5
field was unaligned by 4 bits. It overlaps across two bytes and the host-integer would then beu16
.»» field byte-offset
@byteOffsetOf(__T, __field_name)
will return the offset from base-of-structure to the field's host-integer»» TODO
well-defined memory layout