1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * ASSERTION: C and D compilers try to pack bits as efficiently as possible.
29  *
30  * SECTION: Structs and Unions/Bit-Fields
31  */
32 
33 #pragma D option quiet
34 
35 struct bitRecord1 {
36 	int a : 1;
37 } var1;
38 
39 struct bitRecord2 {
40 	int a : 1;
41 	int b : 3;
42 } var2;
43 
44 struct bitRecord3 {
45 	int a : 1;
46 	int b : 3;
47 	int c : 3;
48 } var3;
49 
50 struct bitRecord4 {
51 	int a : 1;
52 	int b : 3;
53 	int c : 3;
54 	int d : 3;
55 } var4;
56 
57 struct bitRecord5 {
58 	int c : 12;
59 	int a : 10;
60 	int b : 3;
61 } var5;
62 
63 struct bitRecord6 {
64 	int a : 20;
65 	int b : 3;
66 	int c : 12;
67 } var6;
68 
69 struct bitRecord7 {
70 	long c : 32;
71 	long long d: 9;
72 	int e: 1;
73 } var7;
74 
75 struct bitRecord8 {
76 	char a : 2;
77 	short b : 12;
78 	long c : 32;
79 } var8;
80 
81 struct bitRecord12 {
82 	int a : 30;
83 	int b : 30;
84 	int c : 32;
85 } var12;
86 
87 BEGIN
88 {
89 	printf("sizeof (bitRecord1): %d\n", sizeof (var1));
90 	printf("sizeof (bitRecord2): %d\n", sizeof (var2));
91 	printf("sizeof (bitRecord3): %d\n", sizeof (var3));
92 	printf("sizeof (bitRecord4): %d\n", sizeof (var4));
93 	printf("sizeof (bitRecord5): %d\n", sizeof (var5));
94 	printf("sizeof (bitRecord6): %d\n", sizeof (var6));
95 	printf("sizeof (bitRecord7): %d\n", sizeof (var7));
96 	printf("sizeof (bitRecord8): %d\n", sizeof (var8));
97 	printf("sizeof (bitRecord12): %d\n", sizeof (var12));
98 	exit(0);
99 }
100 
101 END
102 /(1 != sizeof (var1)) || (2 != sizeof (var2)) || (3 != sizeof (var3)) ||
103     (4 != sizeof (var4)) || (5 != sizeof (var5)) || (6 != sizeof (var6))
104     || (7 != sizeof (var7)) || (8 != sizeof (var8)) || (12 != sizeof (var12))/
105 {
106 	exit(1);
107 }
108