-1

Possible Duplicate:
What does 'unsigned temp:3' means

I am writing an iOS app and have to deal with some legacy plain ole C:

typedef struct {
    int32_t tid;
    int32_t pos;
    uint32_t bin:16, qual:8, l_qname:8;
    uint32_t flag:16, n_cigar:16;
    int32_t l_qseq;
    int32_t mtid;
    int32_t mpos;
    int32_t isize;
} bam1_core_t;

My question involves the line uint32_t bin:16, qual:8, l_qname:8; can someone please tell me how to access these fields that appear to me some sort of bit-vector sub-field of a 32-bit int.

Thanks,
Doug

Community
  • 1
  • 1
dugla
  • 12,774
  • 26
  • 88
  • 136

2 Answers2

4

These are bit-fields. You access them like any other field in a structure. The number after the colon defines the number of bits used to store that field. For example, the qual:8 means qual can hold values (only) from 0 to 255.

I should add that :0 is special -- it means no more bit-fields should be allocated from the current item (int, uint32_t, etc.) -- the next bit field will come from a new underlying storage unit.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
2

These are bit-fields and you refer to them like this:

bam1_core_t.bin or bam1_core_t.qual etc.

These bit-fields allow you to pack data more tightly. The number to the right of the : specifies how many bits should be allocated to the location associated with the identifier on the left.

The only place you'll see this in C are in structs or unions.

Levon
  • 138,105
  • 33
  • 200
  • 191