0

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

timrau
  • 22,578
  • 4
  • 51
  • 64
S-VPAM
  • 9
  • 1

1 Answers1

1

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 make b and c share the same byte in memory, where b would be 5 of the bits and c would be the other 3 bits.

WhozCraig
  • 65,258
  • 11
  • 75
  • 141
nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • and if you define: unsigned b:2; ?? is only 2 bits, or 1 byte with 2 bits but the another bits is trush? – S-VPAM Jun 20 '15 at 10:26