This is my bitfield
struct {
unsigned char v64 : 1;
unsigned char leg : 7;
} valid;
Then I get the warning:
main.c:17:3: warning: type of bit-field ‘v64’ is a GCC extension [-pedantic]
main.c:18:3: warning: type of bit-field ‘leg’ is a GCC extension [-pedantic]
If I change to int
there is no warning. But I want a bitfield of a byte (unsigned char).
How?
Remove the gcc
-pedantic
option if you don't want to get the warning.
In C99, gcc
issues a warning with -pedantic
but it is permitted to have an implementation defined type for the bit-field (like unsigned char
).
(C99, 6.7.2.1p4) "A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed int, unsigned int, or some other implementation-defined type."
In C90, only int
, unsigned int
and signed int
are permitted.
(C90, 6.5.2.1) "A bit-field shall have a type that is a qualified or unqualified version of one of int, unsigned int, or signed int"
Actually in both C90 and C99 the warning is not required by C (it is undefined behavior in C90 only but C doesn't not require a warning for undefined behavior). The warning is added by gcc
with -pedantic
for information only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With