Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ability to set alignment on struct fields #1512

Closed
Labels
acceptedThis proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.docsproposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
@andrewrk

Description

@andrewrk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.docsproposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp