Your compiler is correct:
C standard, 6.7.2.2p4: "Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined,but shall be capable of representing the values of all the members of the enumeration."
Your implementation seems to use some internal type to represent the enum type, which is valid.
Also see
6.7.2.1p10: "A bit-field is interpreted as having a signed or unsigned integer type consisting of the specified number of bits."
Using an unsigned char
for the bit field is valid.
In general is it bad practice to use homebrew typedefs if standard types are available. C has a mandatory boolean type _Bool
(resp. bool
with supporting constant-macros using stdbool.h
) which has the expected semantics (different from enum
s). Using it would have avoided the problems and is also portable between implementations.
In general, bit-field struct
s are of little use in C. There is no defined layout, underlying or other guarantees which might be expected. Most times a fixed-width integer type and bit-ops is the better choice. Interestingly, _Bool
bit-fields are the type with most guarantees. So using this standard type would have avoided the problem.