Warning when using char unsigned bitfield

This is my bitfield.

struct {
    unsigned char v64 : 1;
    unsigned char leg : 7;
} valid;

Then I get a warning:

main.c:17:3: warning: type of bit-fieldv64is a GCC extension [-pedantic]
main.c:18:3: warning: type of bit-fieldlegis a GCC extension [-pedantic]

If I switch to int, there will be no warning. But I want a byte bit field (unsigned char).

How?

+6
source share
1 answer

Remove the option gcc -pedanticif you do not want to receive a warning.

In C99, gccwarning c is issued -pedantic, but it is permitted to have a specific implementation type for a bit field (for example, unsigned char).

(C99, 6.7.2.1p4) "The bitfield must be of a type that is a qualified or unqualified version of _Bool, signed int, unsigned int, or some other implementation-specific type."

C90 int, unsigned int signed int.

(C90, 6.5.2.1) " , int, unsigned int signed int"

, C90 C99 C ( undefined C90, C undefined). gcc -pedantic .

+11

All Articles