Skip to content
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

Warn that repr(packed) and repr(align) do not guarantee field order, and as a result do not guarantee size #1418

Open
joshlf opened this issue Oct 19, 2023 · 0 comments

Comments

@joshlf
Copy link
Contributor

joshlf commented Oct 19, 2023

While this is already implied by the type layout docs, it's easy to miss since the type layout docs describe reprs as guaranteeing things about the layout, and the special case of repr(packed(1)) does guarantee size.

In particular, call out the following:

  • A repr(packed(N)) struct's size may change depending on field order
    • As a special case, a repr(packed(1)) or repr(packed) struct's size does not depend on field order
  • A repr(align(N)) struct's size may change depending on field order
  • In each of these cases, suggest using repr(C) to guarantee field order if guaranteed size is important
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant