简体   繁体   中英

Can we use bit field for an array which is member of the structure in c?

Can we use bit field of an array which is a part of the structure? Is this possible in C?

typedef struct convert
{
    unsigned char data[7] : 5;                                        //5x7
};

No you can not do that.

  • Bitfields can only be of type int
  • Bitfields are padded to the size of the next element in the struct .

If your array is small enough then you may assign them individual names and make 7 5-bit bitfields, but that is probably not what you want.

Shifting them manually with a macro will be your best bet and as fast.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM