0

I am reading an old hardware code, i find a weird definition of struct:

struct DAA_BITS {
  unsigned long  DAAON          : 1;
  unsigned long  DAARDY         : 1;
  unsigned long                 : 1;
  unsigned long  DAA_TRIM       : 5;
};

I have two questions:

1- What is mean the :1 like definition "unsigned long DAAON : 1;"? did its a common use?

2- In the third value of the struct, there is no name of variable, why to use that?, and how can i access this memory?

I know its looks like the code is not real, but the code is running will(i also debug the code).

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
  • 2
    The `:1`'s are bitfields and the missing name one might be for padding, because that way the first bit of `DAA_TRIM` will be in the expected place. Note that they add to 8 bits. But I honestly didn't know that you can have "*anonymous*" structure fields, so I will not answer this, let's give a chance to someone that really understands this. – Iharob Al Asimi Dec 15 '15 at 15:04
  • 1
    Maybe the third variable is specified in such a way to complete 8 bits and shouldn't be used. – TomTsagk Dec 15 '15 at 15:05
  • Hmm, your question was closed as I was writing an answer. That's a shame, because I don't think any of the "duplicates" actually answer the second part of your question... As @TomTsagk says - it's just a placeholder to pad out the structure. You can't reference it. I'd really strongly recommend getting *the* authoritative book on C: https://en.wikipedia.org/wiki/C_%28programming_language%29 - worth every penny, trust me :) – wally Dec 15 '15 at 15:11
  • See http://www.catb.org/esr/structure-packing/ "The lost art of structure packing " chapter 6 where bitfields are explained – Harald Coppoolse Dec 15 '15 at 15:11
  • Thank you all (@harob, TomTsagk, Wally, HaraldDutch) , sorry for question 1(duplicate question) – Lost In The code Dec 15 '15 at 15:16

0 Answers0