I’m pretty sure I can do this using comptime concatenation of std.builtin.Type.StructField but I’m having some trouble figuring out how to do it, could someone provide an example based on what I have above?
Just a minimal example that works, could obviously use some optimizations. if you are using 0.13, you will have to rename some of the enum fields to match that version.
I haven’t tested it, but I am think that for a packed struct, you are going to want to keep this value as 0, otherwise it would be the normal alignment that is described in the alignment documentation.
i don’t want to lead you down the wrong path, nor was I able to find any documentation dealing specifically with this scenario, so I would recommend either waiting for someone smarter than I to provide some more information, or try it out and ensure it is working as expected.
packed structs do NOT have an alignment of zero,
it’s the same as if it weren’t packed, so normal.
I think the correct way to interpret the documentation on packed structs is in relation to normal structs.
If it’s not specified, it’s the same as normal structs.
Cant say for sure, though.
What is the alignment of second in this example? if this were a standard struct, the answer would be obvious, but I am not so sure what Zig is expecting the user to supply in this scenario when creating the values themselves. I imagine that internally this is just a 32 bit integer with some masking, and alignment isn’t even a factor here for the fields, though I am very open to being corrected.