Skip to content

Proposal: Change ABI alignment of zero-sized types from 0 to 1 #7221

Open
@SpexGuy

Description

@SpexGuy

In #6706 it was decided that pointers to zero-sized types should not be zero sized. As a consequence of this, zero-sized types now need an ABI alignment. This was chosen to be 0, to preserve the invariant that @alignOf(T) <= @sizeOf(T). However, in #6954, @marler8997 made a strong argument for making it 1, to preserve the invariant @alignOf(T) >= 1. This issue exists to continue this discussion now that #6945 has been closed.

Arguments for align 0:

  • Preserves @alignOf(T) <= @sizeOf(T) (is this actually useful though?)
  • You could say that zero sized types are bitpacked, if you put multiple of them together they share the same address
  • Alignment being 0 is always a special case that needs to be handled in pointer type info, so having this special case in @alignOf isn't anything new.

Arguments for align 1:

  • Preserves @alignOf(T) >= 1, removing special cases when using this value.
  • It's kind of weird to make a bit pointer if a zero-sized field follows an align(0) u3 in a non-packed ordered struct. Then again, Zig doesn't have a non-packed ordered struct type that can contain align(0) fields, so this may be a moot point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions