Error trying to define a 1,024-bit (128 Byte) Bit Field

前端 未结 4 1790
走了就别回头了
走了就别回头了 2021-01-06 10:32

I would like to define a large bitfield for the purpose of quickly monitoring the status a very large structure of elements. Here is what I have so far:

#define T         


        
4条回答
  •  情歌与酒
    2021-01-06 10:55

    use

     UINT128 blaha;
    

    You're not defining a bitfield.

    I'm not sure you understand what a bitfield is. I bitfield is a number of bits. Not an array of structs or similar. What exactly are you expecting that your code should do?

    Edit: oh I see now. No, you can't use your own types, just ints.

    Try this (untested code):

    struct bit1024 {
      unsigned char byte[128];
    };
    struct bit1024 foo;
    void
    set(struct bit1024*lala, int n, int v)
    {
      lala->byte[n/8] |= 1<<(n % 8);
      if (!v) {
        lala->byte[n/8] ^= 1<<(n % 8);
      }
    }
    int
    get(struct bit1024*lala, int n)
    {
      return 1 & (lala->byte[n/8] >> (n % 8));
    }
    

提交回复
热议问题