Bit-fields of type other than int?

后端 未结 3 2010
一生所求
一生所求 2020-12-03 18:02

I have a code which uses bit-fields declared as follows

typedef struct my{
    const char *name;
    uint8_t is_alpha : 1;   
    uint8_t is_hwaccel : 1; 
           


        
3条回答
  •  死守一世寂寞
    2020-12-03 18:34

    1] Is there any problems/potential issues in using bit fields of type other than int? Why the warning?

    Since bit-fields are low-level, there may be issues with portability if you are using non-standard types. Hence the warning -- note it is still a warning and not an error.

    2] Are other than int type bit-fileds they allowed by C99 C language specification?

    From the draft of C99:

    6.7.2.1 Structure and union specifiers

    4 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.

提交回复
热议问题