Skip to content

add documentation for packed structs (bitfields) #1513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewrk opened this issue Sep 13, 2018 · 0 comments
Closed

add documentation for packed structs (bitfields) #1513

andrewrk opened this issue Sep 13, 2018 · 0 comments
Labels
Milestone

Comments

@andrewrk
Copy link
Member

This issue extracted from #367

  • packed structs, packed enums, packed unions
  • ability to @bitCast at comptime and @ptrCast at comptime
  • mention that normal structs do not guarantee what size they are, the field order, or padding.
  • zig supports arbitrary integer types
  • normally integer types smaller than 8 bits would still be 1 byte, but in packed structs they are packed
  • bools count as 1 bit
  • taking a pointer to a packed struct field has special syntax
  • mention that the address of a pointer to a packed struct field can be the same address for different fields
  • rename @offsetOf to @byteOffsetOf and add @bitOffsetOf #633 @byteOffsetOf and @bitOffsetOf
  • talk about alignment. packed structs have 1 byte alignment. but if you have a pointer to a packed struct that is overaligned, zig should still understand alignment of fields when appropriate. related: ability to set alignment on struct fields #1512
  • mention that a load/store - especially volatile - might codegen to extra code than if you do it manually. because zig will perform a volatile store 2x, whereas manually you would do the bit shifting once and then write the entire byte at once.
@andrewrk andrewrk added the docs label Sep 13, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant