1 #include <stdint.h>
2 #include <stdio.h>
3 #include <string.h>
4 
main(int argc,char const * argv[])5 int main (int argc, char const *argv[])
6 {
7     struct Bits
8     {
9         uint32_t    : 1, // Unnamed bitfield
10                     b1 : 1,
11                     b2 : 2,
12                     : 2, // Unnamed bitfield
13                     b3 : 3,
14                     : 2, // Unnamed bitfield (this will get removed)
15                     b4 __attribute__ ((aligned(16))),
16                     b5 : 5,
17                     b6 : 6,
18                     b7 : 7,
19                     four : 4;
20     };
21 
22     printf("%lu", sizeof(struct Bits));
23 
24     struct Bits bits;
25     int i;
26     for (i=0; i<(1<<1); i++)
27         bits.b1 = i;        //// break $source:$line
28     for (i=0; i<(1<<2); i++)
29         bits.b2 = i;        //// break $source:$line
30     for (i=0; i<(1<<3); i++)
31         bits.b3 = i;        //// break $source:$line
32     for (i=0; i<(1<<4); i++)
33         bits.b4 = i;        //// break $source:$line
34     for (i=0; i<(1<<5); i++)
35         bits.b5 = i;        //// break $source:$line
36     for (i=0; i<(1<<6); i++)
37         bits.b6 = i;        //// break $source:$line
38     for (i=0; i<(1<<7); i++)
39         bits.b7 = i;        //// break $source:$line
40     for (i=0; i<(1<<4); i++)
41         bits.four = i;      //// break $source:$line
42 
43     struct MoreBits
44     {
45         uint32_t    a : 3;
46         uint8_t       : 1;
47         uint8_t     b : 1;
48         uint8_t     c : 1;
49         uint8_t     d : 1;
50     };
51 
52     struct MoreBits more_bits;
53 
54     more_bits.a = 3;
55     more_bits.b = 0;
56     more_bits.c = 1;
57     more_bits.d = 0;
58 
59     struct EvenMoreBits
60     {
61         uint8_t b1  : 1, b2  : 1, b3  : 1, b4  : 1, b5  : 1, b6  : 1,
62                 b7  : 1, b8  : 1, b9  : 1, b10 : 1, b11 : 1, b12 : 1,
63                 b13 : 1, b14 : 1, b15 : 1, b16 : 1, b17 : 1;
64     };
65 
66     struct EvenMoreBits even_more_bits;
67     memset(&even_more_bits, 0, sizeof(even_more_bits));
68     even_more_bits.b1 = 1;
69     even_more_bits.b5 = 1;
70     even_more_bits.b7 = 1;
71     even_more_bits.b13 = 1;
72 
73 #pragma pack(1)
74     struct PackedBits
75     {
76         char a;
77     	uint32_t b : 5,
78                  c : 27;
79     };
80 #pragma pack()
81     struct PackedBits packed;
82     packed.a = 'a';
83     packed.b = 10;
84     packed.c = 0x7112233;
85 
86     struct LargePackedBits {
87         uint64_t a: 36;
88         uint64_t b: 36;
89     } __attribute__((packed));
90 
91     struct LargePackedBits large_packed =
92       (struct LargePackedBits){ 0xcbbbbaaaa, 0xdffffeeee };
93     struct LargePackedBits *large_packed_ptr = &large_packed;
94 
95     return 0;               //// Set break point at this line.
96 
97 }
98