Possible Duplicate:
What does 'unsigned temp:3' mean?
please what does this notation mean
int a:16;
I found it is code like this and it does compile.
struct name { int a:16; }
struct s
{
int a:1;
int b:2;
int c:7;
};/*size of structure s is 4 bytes and not 4*3=12 bytes since all share the same space provided by int declaration for the first variable.*/
struct s1
{
char a:1;
};/*size of struct s1 is 1byte had it been having any more char _var:_val it would have been the same.*/
This is a bitfield.
This particular bitfield doesn't make much sense as you just could use a 16-bit type and you're wasting some space as the bitfield is padded to the size of int
.
Usually, you are using it for structures that contain elements of bit size:
struct {
unsigned nibble1 : 4;
unsigned nibble2 : 4;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With