Mercurial > hg > CbC > old > device
annotate test/bitfield1.c @ 820:9598ecec0af5
rvalue, RSTRUCT, non parse mode
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 26 Nov 2010 19:38:40 +0900 |
parents | 528fed826f17 |
children | 5313ed059cee |
rev | line source |
---|---|
467 | 1 int printf(const char *format, ...); |
820
9598ecec0af5
rvalue, RSTRUCT, non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
558
diff
changeset
|
2 typedef long long unsigned LLU; |
553 | 3 #ifndef INLINE |
4 #define INLINE | |
5 #endif | |
6 | |
336 | 7 struct aho { |
8 int i:1,j:1; | |
9 char a:7; | |
10 char :7,k:1,:3; | |
11 long long v:33; | |
12 long long w:33; | |
13 long long x:33; | |
14 } a /* = {-1,3,3,3,3} */ ; | |
15 | |
16 union aho1 { | |
17 int i:1,j:1; | |
18 char a:7; | |
19 char :7,k:1,:3; | |
20 long long v:33; | |
21 long long w:33; | |
22 long long x:33; | |
23 } a11 ; | |
24 | |
25 union ll1 { | |
337 | 26 unsigned char a[32]; |
336 | 27 struct { |
28 char a:4; | |
29 long long v:33; | |
30 long long w:33; | |
31 long long x:33; | |
32 } b; | |
33 } ll1; | |
34 | |
35 union ll0 { | |
337 | 36 unsigned char a[32]; |
336 | 37 struct { |
38 char a:4; | |
39 long long v:48; | |
40 long long w:48; | |
41 long long x:48; | |
42 } b; | |
43 } ll0; | |
44 | |
45 | |
46 union ll { | |
337 | 47 unsigned char a[32]; |
336 | 48 struct { |
49 char a:4; | |
50 long long v:56; | |
51 long long w:56; | |
52 long long x:56; | |
53 } b; | |
54 } ll; | |
55 | |
56 union cc { | |
57 int a; | |
58 struct { | |
59 char a:1; | |
60 char b:4; | |
61 char c:7; | |
62 char d:4; | |
63 char e:4; | |
64 char f:4; | |
65 } b; | |
66 } cc; | |
67 | |
68 union ii { | |
69 int a; | |
70 struct { | |
71 int a:1; | |
72 int b:4; | |
73 int c:4; | |
74 int d:4; | |
75 int e:4; | |
76 int f:4; | |
77 } b; | |
78 } ii; | |
545 | 79 void main5(); |
553 | 80 INLINE int |
81 main1() | |
336 | 82 { |
337 | 83 int i; |
558 | 84 printf("#0083:%d\n",a.i); |
336 | 85 |
86 ll1.b.v = -1; | |
820
9598ecec0af5
rvalue, RSTRUCT, non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
558
diff
changeset
|
87 printf("#0086:01:%llx\n",(LLU)ll1.b.v); |
558 | 88 printf("#0087:02:"); for(i=0;i<32;i++) printf("#0082:%02x",ll1.a[i]); printf("#0082:\n"); |
336 | 89 ll1.b.v = 0; |
90 ll1.b.w = -1; | |
558 | 91 printf("#0090:02:"); for(i=0;i<32;i++) printf("#0085:%02x",ll1.a[i]); printf("#0085:\n"); |
336 | 92 ll1.b.w = 0; |
93 ll1.b.x = -1; | |
558 | 94 printf("#0093:02:"); for(i=0;i<32;i++) printf("#0088:%02x",ll1.a[i]); printf("#0088:\n"); |
336 | 95 |
96 ll0.b.v = -1; | |
820
9598ecec0af5
rvalue, RSTRUCT, non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
558
diff
changeset
|
97 printf("#0096:01:%llx\n",(LLU)ll0.b.v); |
558 | 98 printf("#0097:02:"); for(i=0;i<32;i++) printf("#0092:%02x",ll0.a[i]); printf("#0092:\n"); |
336 | 99 ll0.b.v = 0; |
100 ll0.b.w = -1; | |
558 | 101 printf("#0100:02:"); for(i=0;i<32;i++) printf("#0095:%02x",ll0.a[i]); printf("#0095:\n"); |
336 | 102 ll0.b.w = 0; |
103 ll0.b.x = -1; | |
558 | 104 printf("#0103:02:"); for(i=0;i<32;i++) printf("#0098:%02x",ll0.a[i]); printf("#0098:\n"); |
336 | 105 |
106 ll.b.v = -1; | |
820
9598ecec0af5
rvalue, RSTRUCT, non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
558
diff
changeset
|
107 printf("#0106:1:%llx\n",(LLU)ll.b.v); |
558 | 108 printf("#0107:02:"); for(i=0;i<32;i++) printf("#0102:%02x",ll.a[i]); printf("#0102:\n"); |
336 | 109 ll.b.v = 0; |
110 ll.b.w = -1; | |
558 | 111 printf("#0110:02:"); for(i=0;i<32;i++) printf("#0105:%02x",ll.a[i]); printf("#0105:\n"); |
336 | 112 ll.b.w = 0; |
113 ll.b.x = -1; | |
558 | 114 printf("#0113:02:"); for(i=0;i<32;i++) printf("#0108:%02x",ll.a[i]); printf("#0108:\n"); |
336 | 115 |
558 | 116 printf("#0115:char a:1; char b:4; char c:7; char d:4; char e:4; char f:4;\n"); |
336 | 117 cc.b.a = -1; |
558 | 118 printf("#0117:a:%08x\n",cc.a); |
336 | 119 cc.b.b = -1; |
558 | 120 printf("#0119:b:%08x\n",cc.a); |
336 | 121 cc.b.c = -1; |
558 | 122 printf("#0121:c:%08x\n",cc.a); |
336 | 123 cc.b.d = -1; |
558 | 124 printf("#0123:d:%08x\n",cc.a); |
336 | 125 cc.b.e = -1; |
558 | 126 printf("#0125:e:%08x\n",cc.a); |
336 | 127 cc.b.f = -1; |
558 | 128 printf("#0127:f:%08x\n",cc.a); |
129 printf("#0128:3:%d %d\n",cc.b.c,cc.b.d); | |
336 | 130 cc.a = -1; |
558 | 131 printf("#0130:f:%08x\n",cc.a); |
336 | 132 cc.b.a = 0; |
558 | 133 printf("#0132:a:%08x\n",cc.a); |
336 | 134 cc.b.b = 0; |
558 | 135 printf("#0134:b:%08x\n",cc.a); |
336 | 136 cc.b.c = 0; |
558 | 137 printf("#0136:c:%08x\n",cc.a); |
336 | 138 cc.b.d = 0; |
558 | 139 printf("#0138:d:%08x\n",cc.a); |
336 | 140 cc.b.e = 0; |
558 | 141 printf("#0140:e:%08x\n",cc.a); |
336 | 142 cc.b.f = 0; |
558 | 143 printf("#0142:f:%08x\n",cc.a); |
144 printf("#0143:3:%d %d\n",cc.b.c,cc.b.d); | |
336 | 145 cc.a = 0; |
558 | 146 printf("#0145:f:%08x\n",cc.a); |
336 | 147 cc.b.a = 1; |
558 | 148 printf("#0147:a:%08x\n",cc.a); |
336 | 149 cc.b.b = 1; |
558 | 150 printf("#0149:b:%08x\n",cc.a); |
336 | 151 cc.b.c = 1; |
558 | 152 printf("#0151:c:%08x\n",cc.a); |
336 | 153 cc.b.d = 1; |
558 | 154 printf("#0153:d:%08x\n",cc.a); |
336 | 155 cc.b.e = 1; |
558 | 156 printf("#0155:e:%08x\n",cc.a); |
336 | 157 cc.b.f = 1; |
558 | 158 printf("#0157:f:%08x\n",cc.a); |
159 printf("#0158:3:%d %d\n",cc.b.c,cc.b.d); | |
336 | 160 cc.a = -1; |
558 | 161 printf("#0160:f:%08x\n",cc.a); |
336 | 162 cc.b.a = 1; |
558 | 163 printf("#0162:a:%08x\n",cc.a); |
336 | 164 cc.b.b = 1; |
558 | 165 printf("#0164:b:%08x\n",cc.a); |
336 | 166 cc.b.c = 1; |
558 | 167 printf("#0166:c:%08x\n",cc.a); |
336 | 168 cc.b.d = 1; |
558 | 169 printf("#0168:d:%08x\n",cc.a); |
336 | 170 cc.b.e = 1; |
558 | 171 printf("#0170:e:%08x\n",cc.a); |
336 | 172 cc.b.f = 1; |
558 | 173 printf("#0172:f:%08x\n",cc.a); |
174 printf("#0173:3:%d %d\n",cc.b.c,cc.b.d); | |
336 | 175 |
176 ii.b.a = -1; | |
558 | 177 printf("#0176:6:%08x\n",ii.a); |
336 | 178 ii.b.d = -1; |
558 | 179 printf("#0178:6:%08x\n",ii.a); |
180 printf("#0179:5:%d %d\n",ii.b.a,ii.b.d); | |
336 | 181 |
182 main5(); | |
183 return 0; | |
184 } | |
556 | 185 INLINE // too late |
545 | 186 void |
336 | 187 main5() |
188 { | |
189 int i,j,bit=1; | |
190 for(i=0;i<32;i++,bit<<=1) { | |
191 ii.a = bit; | |
558 | 192 printf("#0191:%08x:ii.b.a=%d ii.b.b=%d ii.b.c=%d ii.b.d=%d ii.b.e=%d ii.b.f=%d\n",bit, |
336 | 193 ii.b.a,ii.b.b,ii.b.c,ii.b.d,ii.b.e,ii.b.f); |
194 } | |
195 bit=1; | |
196 for(i=0;i<32;i++,bit<<=1) { | |
197 cc.a = bit; | |
558 | 198 printf("#0197:%08x:cc.b.a=%d cc.b.b=%d cc.b.c=%d cc.b.d=%d cc.b.e=%d cc.b.f=%d\n",bit, |
336 | 199 cc.b.a,cc.b.b,cc.b.c,cc.b.d,cc.b.e,cc.b.f); |
200 } | |
337 | 201 ll.a[0]=ll.a[1]=ll.a[2]=ll.a[3]= ll.a[4]=ll.a[5]=ll.a[6]=ll.a[7]=0; |
341 | 202 ll.b.v=ll.b.w=ll.b.x = 0; |
337 | 203 for(i=7;i>=0;i--) { |
336 | 204 bit=1; |
205 for(j=0;j<32;j++,bit<<=1) { | |
206 ll.a[i] = bit; | |
558 | 207 printf("#0206:02:%02x %02x %02x %02x %02x %02x %02x %02x\n", |
336 | 208 ll.a[0],ll.a[1],ll.a[2],ll.a[3], |
209 ll.a[4],ll.a[5],ll.a[6],ll.a[7] | |
210 ); | |
820
9598ecec0af5
rvalue, RSTRUCT, non parse mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
558
diff
changeset
|
211 printf("#0210: ll.b.v=%lld ll.b.w=%lld ll.b.x=%lld\n",(LLU)ll.b.v,(LLU)ll.b.w,(LLU)ll.b.x); |
336 | 212 } |
337 | 213 ll.a[i]=0; |
336 | 214 } |
215 } | |
216 | |
553 | 217 int |
218 main() | |
219 { | |
220 main1(); | |
221 return 0; | |
222 } |