0

I am testing some code and I'm trying to understand what a structure does. The code is as follows

typedef struct
{
  uint8_t      :5;
  uint8_t Index:3;
} foo;

I searched for a while and couldn't find an answer. What does the : "operator" do and what's the significance of 5 and 3?

user3217278
  • 320
  • 3
  • 9
  • @Deduplicator: This isn't *quite* a duplicate. The linked question asks about normal bit fields; this one asks about unnamed bit fields. – Keith Thompson Oct 24 '14 at 21:04

3 Answers3

1

That's not an operator. That's C's 'bit-field' syntax. The first unnamed variable here is 5 bits followed by 'Index' which is 3 bits.

See Wikipedia

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
0

Its a bit field. The number after the colon is how many bits of memory each variable takes up. there are lots of answers that give lots more info on this on SO already -

":" (colon) in C struct - what does it mean?

Community
  • 1
  • 1
Ctrl_Alt_Defeat
  • 3,933
  • 12
  • 66
  • 116
0

Code fragment in C structure uint8_t : 5 what does that mean?

An unnamed bit-field is used to provide padding between adjacent bit-field members. Here there is a 5-bit padding before the 3-bit Index bit-field.

ouah
  • 142,963
  • 15
  • 272
  • 331