Bit-fields of type other than int?

后端 未结 3 2039
一生所求
一生所求 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:51

    Why not use int? The actual implementation of bitfields varies from compiler to compiler. If you want to write portable code, use int. If you want to create a small structure, or a structure of a fixed number of bytes, or a structure where the bits are in a fixed position, don't use bitfields. Create a uint8_t member called something like flags and define macros to use as bitmasks.

提交回复
热议问题