Skip to content

Offset/alignment for 0 bit types #4016

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

Open
daurnimator opened this issue Dec 31, 2019 · 2 comments
Open

Offset/alignment for 0 bit types #4016

daurnimator opened this issue Dec 31, 2019 · 2 comments
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@daurnimator
Copy link
Contributor

daurnimator commented Dec 31, 2019

e.g. If I have a packed struct with comptime parametized types, I don't want to have things not work when a field is passed as void/u0/struct{}. Instead, the offset should be right where it is (note that this differs from C where a 0-sized field aligns to the next byte boundary)

    const a = packed struct {
        foo: i32,
        bar: u0,
        baz: i32,
    };
    assert(@bitOffsetOf(a, "bar") == @bitOffsetOf(a, "baz"));

Another use case for this is helping to create structs with trailing data:

const mystruct = packed struct {
    foo: X,
    bar: Y,
    trailing_data:  @alignOf(Z) void,
}

const slice = try allocator.alignedAlloc(u8, @alignOf(mystruct), @sizeOf(mystruct) + extra_size);
const a = @ptrCast(*mystruct, slice.ptr);
const trailing_data = @ptrCast([*]Z, &a.trailing_data);
@daurnimator daurnimator added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Dec 31, 2019
@andrewrk andrewrk added this to the 0.7.0 milestone Dec 31, 2019
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@SpexGuy SpexGuy added the accepted This proposal is planned. label Nov 21, 2020
@SpexGuy
Copy link
Contributor

SpexGuy commented Nov 21, 2020

With the decision in #6706, pointers to zero-sized values are now real pointers. This also means that offset and alignment will behave as described in this issue.

@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 20, 2021
@andrewrk
Copy link
Member

I believe this is fixed now and only task left is to ensure there is behavior test coverage.

@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Aug 24, 2022
@andrewrk andrewrk modified the milestones: 0.10.1, 0.11.0 Jan 10, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jun 29, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants