Possible Duplicate:
What does this C++ code mean?
What does ‘unsigned temp:3’ mean?
I have seen one small c program recently.There in that program,the structure was declared in this manner which I could not understand.
struct
{
mynode *node;
unsigned vleft :1;
unsigned vright :1;
}save[100];
Here node is pointer to some other structure.
Can some one please explain what unsigned vleft :1; unsigned vright :1; are? And I could not find any datatype assigned to vleft and vright.What is the reason for that?
Thanks.
The default type assumed here is
unsigned int, this is assumed by the compiler when you specify justunsigned.The bitfield syntax
unsigned vleft : 1specifies the width in bits of the data field, in this situation it means that it’s a single bit flag (which can be either0or1). This is used to pack many fields of the structure in less bits (when you don’t need to waste, like in this case, a wholecharorintfor just storing a flag).