zig icon indicating copy to clipboard operation
zig copied to clipboard

Allow specifying the alignment of extern structs

Open wooster0 opened this issue 1 year ago • 3 comments

This is a follow-up to #10113: https://github.com/ziglang/zig/issues/10113#issuecomment-1241789307 We need an addition to the language that allows us to specify the alignment of extern structs. The UEFI libs are particularly broken because since #10113 any packed struct with an array or any extern struct in it isn't a valid packed type. In order to make std.os.uefi work with self-hosted, #12899 was an effort to make it easier to add align(1) to every field of a struct. The problem is that it might not work that well considering that structs with decls can't be reified because of #6709. But instead of allowing #6709 (which might be a bad idea) and then using CPacked, it's probably best to allow specifying the alignment of extern structs at the language level.

A good syntax for this would be extern struct align(alignment) {}.

See also: #12745 #12897 #12993

CC @fifty-six

wooster0 avatar Sep 29 '22 17:09 wooster0

To clarify, this would specify the default alignment of every field within the struct? (i.e., the effective alignment of the extern struct might differ after explicit field alignments are applied?)

Somewhat related, esp. regarding syntax: https://github.com/ziglang/zig/issues/8643

topolarity avatar Sep 30 '22 17:09 topolarity

Yes, that's basically what it does. It's like applying that same alignment manually to every field in the struct.

wooster0 avatar Oct 01 '22 08:10 wooster0

To clarify, this would specify the default alignment of every field within the struct?

I wouldn't expect that from the syntax: i would expect it to be the minimum alignment for the entire struct (i.e. the first field of the struct)

daurnimator avatar Oct 21 '22 07:10 daurnimator