i dont know whats mean "unsigned :5",
for example if i create these:
int a:8;
unsigned b:8;
is b a integer?
and another question:
in a union with these values:
union
{ long quad;
long duble;
char byte;
struct {
unsigned :16;
unsigned :16;
unsigned :16;
unsigned :15;
unsigned bit1:1;
} bits;
}pes;
pes.quad=0x12345678;
pes.duble=0xabcd;
pes.byte=0xef;
pes.bits.bit1=1;
why in Adress
is: ef ab 00 00 cc cc cc cc
I thought it would be ef ab 34 12 00 00 00 80
The
:
introduces a bit field, which is a value in a struct of a particular logical type but with an actual size measured in bits. This is useful for defining structures that access individual bits of a value (e.g. to extract flag bits from a word).For example, defining
unsigned b:5; unsigned c:3;
would makeb
andc
share the same byte in memory, whereb
would be 5 of the bits andc
would be the other 3 bits.