Skip to content

Add meta function CPacked to add align(1) to extern structs #12899

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
wants to merge 1 commit into from

Conversation

fifty-six
Copy link
Contributor

This allows for easier FFI with C APIs that use large amounts of packed structs by allowing the omission of align(1) on every field declaration.

Motivation behind this being for UEFI ffi as almost every struct there is packed.

This allows for easier FFI with C APIs that use large amounts
of packed structs by allowing the omission of align(1) on every
field declaration.
@wooster0
Copy link
Contributor

Sadly this isn't actually going to work if the extern struct has any decls inside it...

    const S3 = CPacked(extern struct {
        a: u8,
        b: u8,
        c: u16,
        d: u8,
        fn x() void {}
    }, .{ .b = @alignOf(u16) });
x.zig:149:12: error: reified structs must have no decls
    return @Type(.{
           ^~~~~
x.zig:168:23: note: called from here
    const S3 = CPacked(extern struct {
               ~~~~~~~^

Yet another reason for #6709

So I don't think this will work as a permanent solution. It would work as a better temporary one if #6709 was solved but ultimately the language needs an addition to make this easier.

@fifty-six
Copy link
Contributor Author

fifty-six commented Sep 29, 2022

if anyone is interested in this for just simple data I can reopen but without decls I'm not sure this is great and a lang feature would be better

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

Successfully merging this pull request may close these issues.

2 participants