#Is it better to have a `usize` of flags, or a struct with those flags (`u1`'s)?

1 messages · Page 1 of 1 (latest)

late glacier
#

basically, I have a structure for which I also need to store some flags. in C, I would store it in an unsigned int and each bit represents a different flag. Is this done in the same way in zig, or would a struct of u1's with some default values:

const options = struct {
    option1: u1 = 0,
    option2: u1 = 0,
    option3: u1 = 1,
    ...
}

be better? Also, much less important, name it flags or options?

worn junco
dusky gull
#

^
rn each option will take up a byte which is pretty unfortunate

#

with a packed struct its fully bit packed

late glacier
#

Thank you, it is exactly what I need

#

More subjectively, do you call this flags or options?

#

Also, I am gessing that if all of the fields don't reach 8bits altogether, the struct still takes up 1 byte?