HomeFreeBSD

Support byte-sized enums

Description

Support byte-sized enums

To that end add enum_uint8_decl and enum_uint8.

By default enums take 4 bytes, but vast majority of them have values
which would fit in a byte.

One can try to workaround the problem by using bitfields, like so:
enum some_small_enum foo:8;

but that's ugly and runs into trouble when using atomic_load (you can't
take an address of a bitfield, even if it is sized to a multiply of a
byte).

Both gcc 13 and clang support specifying the size, and for older
variants one can fallback to the "packed" attribute.

Names are mangled in order to avoid mix use with plain enum.

Reviewed by:
Differential Revision: https://reviews.freebsd.org/D39031

Details

Provenance
mjgAuthored on Mar 12 2023, 7:29 PM
Differential Revision
D39031: Support byte-sized enums
Parents
rG9def8ea689ed: vfs: list enums on separate lines
Branches
Unknown
Tags
Unknown