Hi all,
I saw this somewhere.
UINT32 x : 1;
May I know what is the purpose of declaring the data type to 32 bits, but only 1 bit is in use? Is this related to hardware logic?
Thanks for the help.
Hi all,
I saw this somewhere.
UINT32 x : 1;
May I know what is the purpose of declaring the data type to 32 bits, but only 1 bit is in use? Is this related to hardware logic?
Thanks for the help.
Well, UINT32 is a "unsigned long" (or "unsigned int" - both may well be 32 bits, unsigned long may also be 64 bits), which tells the compiler that the bit is to fit inside an unsigned long word. It's still only represented with one bit, and there's no REAL difference between that and "unsigned short" or "unsigned char". The size of the struct will be at least 32 bits [assuming of course that UINT32 is correctly defined and no other rules in the system will extend the structure (e.g. the compiler has a rule that no structure can be smaller than 64 bits)].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
what i would like to ask is why UINT32 is used instead of UINT8 etc?
what is the usage of this definition?
UINT32 x : 1;
':1' means only one bit is used, how about other 31 bits?
if i have 2 definition below,
UINT32 x : 1;
UINT32 y : 1;
there will be how many UINT32 is in use?
In your second case, there's one UINT32 [although this is also completely guaranteed - see below], which has two bits defined (most likely adjascent bits, but it's not guaranteed by any of the C/C++ standards - the internal structure of bit fields is entirely up to the compiler vendor).
Not sure if this clarifies things much, but it describes in different words what I've just said:
http://publib.boulder.ibm.com/infoce...c03defbitf.htm
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.