1#import <objc/NSObject.h>
2
3typedef struct {
4 unsigned char fieldOne : 1;
5 unsigned char fieldTwo : 1;
6 unsigned char fieldThree : 1;
7 unsigned char fieldFour : 1;
8 unsigned char fieldFive : 1;
9} UCBitFields;
10
11@interface HasBitfield : NSObject {
12@public
13 unsigned field1 : 1;
14 unsigned field2 : 1;
15};
16
17-(id)init;
18@end
19
20@implementation HasBitfield
21-(id)init {
22 self = [super init];
23 field1 = 0;
24 field2 = 1;
25 return self;
26}
27@end
28
29@interface ContainsAHasBitfield : NSObject {
30@public
31 HasBitfield *hb;
32};
33-(id)init;
34@end
35
36@implementation ContainsAHasBitfield
37-(id)init {
38 self = [super init];
39 hb = [[HasBitfield alloc] init];
40 return self;
41}
42
43@end
44
45@interface HasBitfield2 : NSObject {
46@public
47 unsigned int x;
48
49 unsigned field1 : 15;
50 unsigned field2 : 4;
51 unsigned field3 : 4;
52}
53@end
54
55@implementation HasBitfield2
56- (id)init {
57 return (self = [super init]);
58}
59@end
60
61int main(int argc, const char * argv[]) {
62 ContainsAHasBitfield *chb = [[ContainsAHasBitfield alloc] init];
63 HasBitfield2 *hb2 = [[HasBitfield2 alloc] init];
64
65 hb2->x = 100;
66 hb2->field1 = 10;
67 hb2->field2 = 3;
68 hb2->field3 = 4;
69
70 UCBitFields myField = {0};
71 myField.fieldTwo = 1;
72 myField.fieldFive = 1;
73
74 return 0; // break here
75}
76
77

source code of lldb/test/API/lang/objc/bitfield_ivars/main.m